Cameron Walser
Cameron Walser

Reputation: 13

Get file path, use as a variable in a keystroke (applescript)

I'm trying to write a script that will get the selected file's path and type it into terminal for me. I'm new to scripting so this is all I have so far - the mistakes will be nice and obvious!

set filepath to (currently selected file's path, or drag-and-dropped file...?)

activate application "Terminal"

tell application "System Events" to keystroke "./aerender -project " + "'$filepath'"

tell application "System Events" to keystroke return**

I know that's totally wrong but hopefully it give the idea of what I'm trying to do.

Thanks in advance!

Upvotes: 0

Views: 672

Answers (1)

jweaks
jweaks

Reputation: 3792

You can script Terminal directly... no need for UI scripting.

tell application "Finder" to set filePath to POSIX path of file (selection as string)
set filePath to quoted form of filePath
tell application "Terminal"
    activate
    set currentTab to do script ("./aerender -project " & filePath)
end tell

Upvotes: 0

Related Questions