hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

passing arguments to hs.osascript.applescriptFromFile

Open vtacquet opened this issue 1 year ago • 1 comments

Hi,

Is it possible to pass arguments to an existing Apple Script file with hs.osascript.applescriptFromFile? Otherwise I have to rewrite the file into hs.osascript.applescript([[ ]]) logic and maintain 2 sources.

Thank you Vincent

vtacquet avatar Sep 14 '23 06:09 vtacquet

I ran into this same issue. A possible workaround is to pass the parameters via the Applescript command run script ... with parameters.


set myApplescriptFile to "Macintosh HD:Users:vincent:.hammerspoon:my-applescript.scpt" as alias
run script myApplescriptFile with parameters {"one", "two"}

So your hammerspoon script might be something like


source = [[
    set myApplescriptFile to "Macintosh HD:Users:vincent:.hammerspoon:my-applescript.scpt" as alias
    run script myApplescriptFile with parameters {"one", "two"}
]]
hs.osascript.applescript(source)

pimlottc avatar Nov 10 '23 20:11 pimlottc