GregM
GregM

Reputation: 3734

How to get filename to activated application within applescript?

I am creating an applescript that opens terminal, I am dragging a file onto the script (using automater) and want the directory/name of file to be fed into my terminal application

    on run {input, parameters}
    tell application "Terminal"
        activate
        do script with command "qpdf --qdf arg1 output.pdf"
    end tell
end run

Upvotes: 0

Views: 84

Answers (1)

adayzdone
adayzdone

Reputation: 11238

You don't need to use Automator. Save this script as an application instead...

    on open of droppedItems
    tell application "Terminal"
        if not (exists window 1) then reopen
        activate
    end tell

    repeat with anItem in droppedItems
        set itemPath to POSIX path of anItem
        tell application "Terminal"
            do script "qpdf --qdf " & quoted form of itemPath & " output.pdf" in window 1
            -- do script "echo " & quoted form of itemPath in window 1
        end tell
    end repeat
end open

Upvotes: 1

Related Questions