Automator to run AppleScript for a shell script

applescriptautomatorperl

For a selected file in Finder, I like to run a perl script using Services. I created an Automator process that runs an AppleScript:

on run {input, parameters}
    tell application "Terminal"
        activate
        do script "/Users/myaccountname/Applications/TeXcount_3_0/texcount.pl \"" & (input as string) & "\""
    end tell
end run

The only problem is that the selected filename appears as something like:

"Macintosh HD:Users:myaccountname:Documents:texfile.tex"

which the perl script cannot understand. How can I make it a UNIX-like filename?

Best Answer

You'll need to get the POSIX path of the input file:

on run {input, parameters}
    tell application "Terminal"
        activate
        do script "/Users/myaccountname/Applications/TeXcount_3_0/texcount.pl \"" & ( POSIX path of input as string) & "\""
    end tell
end run

I found the answer over at StackOverflow.