applescript to run a command on each file dropped on to it

These lines will run /path/command with a first parameter of the file name that got
dropped on the Apple Script app:


on open (ItemList)
repeat with thisItem in ItemList
do shell script "/path/command " & POSIX path of thisItem
end repeat
end open

Simple. And unintuitive. AppleScript would rule the world if it would have JavaScript syntax for instance. Instead apple idiots made “Automator”. What a silly piece of shit. Only fanboys spend time to learn a buggy and totally non portable interface like AppleScript or Automator. I could have bothered with Windows if I would want that. Oh, the script above fails to work when there are spaces in the name. Thanks AppleScript.

3 Responses to “applescript to run a command on each file dropped on to it”

  1. Martin Michel Says:

    It’s not AppleScript’s fault, that the command fails when your passed file path contains spaces. You must quote it (also in Python/Ruby/Perl/etc.):

    do shell script “/path/command ” & (quoted form of Posix path of thisItem)

    In addition it is good practice to convert the whole command to UTF-8 before executing it with ‘do shell script’, as AppleScript is - by default - always UTF-16:

    set command to command as «class utf8»
    do shell script command

    If you don’t like the AppleScript syntax, give appscript a try:

    http://appscript.sourceforge.net/

    HTH!

  2. Andreas Wacker Says:

    ok, that does make sense.

    Thanks for the hint with AppScript. Very interesting.

  3. Andreas Wacker Says:

    This page http://developer.apple.com/technotes/tn2002/tn2065.html has a decent collection of applescript / script hints and questions.

Leave a Reply

You must be logged in to post a comment.