2

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?

2 Answers 2

4

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.

1

You can also use quoted form of to escape the arguments:

on run {input, parameters}
    tell application "Terminal"
        do script "printf %s\\\\n " & quoted form of POSIX path of item 1 of input & ">/tmp/a"
    end tell
end run

Or if the service can receive multiple files as input:

on run {input, parameters}
    set args to ""
    repeat with f in input
        set args to args & " " & quoted form of POSIX path of f
    end repeat
    tell application "Terminal"
        do script "printf %s\\\\n " & args & ">/tmp/a"
    end tell
end run

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.