I would like to pass variables from Hammerspoon into AppleScript and vice versa. Here is the general idea of what I am trying to do:
--Within Hammerspoon do loop: Choose a random number between 1–26
----- Within AppleScript: Create variable string called alphabet
----- Within AppleScript: Say the item number corresponding to randNum
----- Within AppleScript: Create new variable randLetter corresponding to randNum
--Out of AppleScript, but still within Hammerspoon do function: alert.show(i..randNum..randLetter)
Here is my idea, despite knowing that neither ApplecScript nor Hamemrspoon are accepting variables from each other:
---- [[ Pass hammerspoon variable into AppleScript and variable from inside AppleScript out to Hammerspoon]] ----
hs.hotkey.bind ({"ctrl"}, "1", function()
iteration = 0
for i = 1, 2/1, 1
do
iteration = i
randNum = hs.math.randomFromRange(1, 26)
hs.osascript.applescript([[
set alphabet to "abcdefghijklmnopqrstuvwxyz"
say item {randNum} of alphabet -- HERE I WANT TO USE THE VARIABLE randNum WHICH WAS DEFINED OUTSIDE OF APPLECSCRIPT
set randLetter to item {randNum} of alphabet -- AGAIN MAKE USE OF randNum
]])
hs.alert.show(i .. ": " .. randNum .. ": " randLetter) -- HERE I WANT TO USE THE VARIABLE randLetter, WHICH WAS DEFINED IN THE APPLESCRIPT
end
end
)
Thanks for any advice