Category Archive: Real World Problems

Snow Leopard “Upload to temporary directory” service

If you’re like me, you’ll most probably have a temp directory on your webserver where you can put stuff which shouldn’t last long on the internets. Mine gets deleted automatically after 14 days via cron. The automatic deletion was convenient enough, but with the new services menu in Snow Leopard it gets even better. You can super easily whip up your own service to upload selected files from the Finder with one click to your server.

See the detailed steps after the jump …
Click here to read more »

Remove .svn files with bash

Just a quick reminder, since I always forget this one ...

  1. find . -name .svn -exec rm -rf {} \;

Open unread items from Vienna in your browser

With this script you can open the unread items of a selected feed in Vienna in either Safari (on per tab) or your default browser. Additionally the script will mark all unread items as read in your selected feed.

Open Vienna, select your feed you want to read and run this script. If you're using Safari you'll need to activate "Enable access for assistive devices" in the Universal Access preference pane (if you haven't already done so). If you're using a browser other than safari you can change

openFeedInSafari(theURL)

to

openFeed(theURL)

in line 18.

In order to run this script more elegantly than double-click it from Finder you may prefer to run it from scriptmenu

  1. set theArticleURLs to {}
  2.  
  3. if UIscript_check() is not false then
  4.     try
  5.         tell application "Vienna"
  6.             activate
  7.             set theArticleList to article of current folder
  8.             repeat with anArticle in theArticleList
  9.                 set theURL to link of anArticle
  10.                 if (read of anArticle is not true) then
  11.                     set theArticleURLs to theArticleURLs & theURL
  12.                 end if
  13.             end repeat
  14.             mark all read in current folder
  15.         end tell
  16.        
  17.         repeat with theURL in theArticleURLs
  18.             openFeedInSafari(theURL)
  19.         end repeat
  20.     on error error_message
  21.         display dialog error_message
  22.     end try
  23. end if
  24.  
  25. on openFeed(anURL)
  26.     ignoring application responses
  27.         open location anURL
  28.     end ignoring
  29. end openFeed
  30.  
  31.  
  32. on openFeedInSafari(anURL)
  33.     my new_tab()
  34.     tell application "Safari"
  35.         set the URL of document 1 to anURL
  36.     end tell
  37. end openFeedInSafari
  38.  
  39. on new_tab()
  40.     try
  41.         tell application "Safari"
  42.             activate
  43.         end tell
  44.         tell application "System Events"
  45.             tell process "Safari"
  46.                 tell menu bar 1
  47.                     tell menu 3
  48.                         click menu item 2
  49.                     end tell
  50.                 end tell
  51.             end tell
  52.         end tell
  53.     on error error_message
  54.         return error_message
  55.     end try
  56. end new_tab
  57.  
  58.  
  59.  
  60.  
  61.  
  62. ----Apple User Interface check----------------------------------------
  63.  
  64. on UIscript_check()
  65.     -- get the system version
  66.     set the hexData to system attribute "sysv"
  67.     set hexString to {}
  68.     repeat 4 times
  69.         set hexString to ((hexData mod 16) as string) & hexString
  70.         set hexData to hexData div 16
  71.     end repeat
  72.     set the OS_version to the hexString as string
  73.     if the OS_version is less than "1030" then
  74.         display dialog "This script requires the installation of " & ¬
  75.             "Mac OS X 10.3 or higher." buttons {"Cancel"} ¬
  76.             default button 1 with icon 2
  77.         return false
  78.     end if
  79.     -- check to see if assistive devices is enabled
  80.     tell application "System Events"
  81.         set UI_enabled to UI elements enabled
  82.     end tell
  83.     if UI_enabled is false then
  84.         tell application "System Preferences"
  85.             activate
  86.             set current pane to ¬
  87.                 pane "com.apple.preference.universalaccess"
  88.             set the dialog_message to "Dieses Script nutzt " & ¬
  89.                 "die eingebaute User Interface Scripting " & ¬
  90.                 "Architektur von Mac OS X, " & ¬
  91.                 "welche momentan deaktiviert ist." & return & return & ¬
  92.                 "Sie können GUI Scripting aktivieren indem Sie " & ¬
  93.                 "die Checkbox “Zugriff für Hilfsgeräte aktivieren” " & ¬
  94.                 "im Bedienungshilfen Einstellungsdialog auswählen."
  95.             display dialog dialog_message buttons {"Abbrechen"} ¬
  96.                 default button 1 with icon 1
  97.         end tell
  98.         return false
  99.     end if
  100.     return true
  101. end UIscript_check

Update your Wordpress installation via Ant

After toying a little with Ant I came up with this task

  1. <project name="update_wordpress" basedir="../" default="all">
  2.    
  3.    
  4.     <target name="init">
  5.         <property name="ftp_user" value="john_doe" />
  6.         <property name="ftp_pass" value="secret" />
  7.         <property name="ftp_server" value="www.foo.com" />
  8.         <property name="ftp_path" value="ftp/path/to/your/blog" />
  9.     </target>  
  10.    
  11.    
  12.     <target name="download_latest">
  13.         <mkdir dir="tmp" />
  14.         <get src="http://counter.wordpress-deutschland.org/dlcount.php?id=static&amp;url=/de-edition/latest.zip" dest="tmp/latest.zip" />
  15.         <unzip src="tmp/latest.zip" dest="tmp" />
  16.         <delete file="tmp/latest.zip" />
  17.         <fail message="there's something wrong with the wordpress archive">
  18.             <condition>
  19.                 <not>
  20.                     <available file="tmp/wordpress" property="wordpressinstall.exists" />
  21.                 </not>
  22.             </condition>       
  23.         </fail>
  24.     </target>
  25.    
  26.    
  27.     <target name="backup" depends="init">
  28.       <mkdir dir="backup" />
  29.       <ftp action="recv"
  30.            server="${ftp_server}"
  31.            userid="${ftp_user}"
  32.            password="${ftp_pass}"      
  33.            remotedir="${ftp_path}"
  34.            passive="yes"           
  35.            verbose="yes">
  36.         <fileset dir="backup">
  37.             <include name="**" />
  38.         </fileset>
  39.       </ftp>       
  40.     </target>  
  41.    
  42.    
  43.     <target name="update" depends="init,download_latest">
  44.         <ftp action="del"
  45.              server="${ftp_server}"
  46.              userid="${ftp_user}"
  47.              remotedir="${ftp_path}"
  48.              passive="yes"
  49.              verbose="yes"
  50.              password="${ftp_pass}">
  51.             <fileset>
  52.                 <include name="**" />
  53.                 <exclude name=".htaccess" />
  54.                 <exclude name="wp-content" />
  55.                 <exclude name="wp-content/**" />
  56.                 <exclude name="wp-config.php" />
  57.             </fileset>
  58.         </ftp>
  59.    
  60.         <ftp server="${ftp_server}"
  61.              remotedir="${ftp_path}"
  62.              userid="${ftp_user}"
  63.              password="${ftp_pass}"
  64.              passive="yes"
  65.              verbose="yes"
  66.              binary="yes">
  67.             <fileset dir="tmp/wordpress">
  68.                 <include name="**" />
  69.                 <exclude name="wp-content" />
  70.                 <exclude name="wp-content/**" />
  71.                 <exclude name="*.html" />
  72.                 <exclude name="*.txt" />
  73.                 <exclude name="wp-config-sample.php" />
  74.             </fileset>
  75.         </ftp>     
  76.     </target>
  77.    
  78.    
  79.     <target name="all" depends="init,download_latest,backup,update">
  80.         <deltree dir="tmp" />
  81.         <echo message="Update finished." />
  82.     </target>
  83.    
  84. </project>

Be careful, this Ant file downloads the german version of Wordpress. You also need to have commons-net and jakarta-oro in your %ANT_HOME%/lib installed in order to have this work. See here. Additional I won't be responsible if you screw up your blog or other relevant data. Be sure to make an manual backup first.