newbie confusion: how to run my new Lua script on demand

53 views
Skip to first unread message

Joel D Canfield

unread,
Aug 1, 2023, 2:23:08 AM8/1/23
to Hammerspoon
Using Hammerspoon to automate apps which aren't exposed to AppleScript (Affinity Photo, in this case.)

Wrote the Lua to open a new Photo document* which works as expected in the Hammerspoon console. Is this the only way to run this, open Hammerspoon and put the code there? I assume I'm missing something obvious.

Hoping for a keyboard shortcut to run this so I can, from anywhere on my Mac, fire up Photo with a new document.

joel

*Affinity apps get confused by Mac dual monitor setups and open new documents on the non-primary monitor, BEHIND all the dialog boxes. So upon creating a new document, the first thing I do, multiple times a day, is use my existing keyboard shortcut from, erm, Karabiner or something else I've forgotten because it's late and I'm tired, and move the document to the correct monitor. My Lua/Hammerspoon script makes this all happen automagically.

Chris Jones

unread,
Aug 2, 2023, 7:18:21 AM8/2/23
to Joel D Canfield, Hammerspoon
Hey

If you click on the Hammerspoon menubar icon there is an "Open Config" item, which will load a text editor with the contents of ~/.hammerspoon/init.lua

Anything you place in that file will be executed by Hammerspoon when it launches, so you could place your window manipulating Lua into a function and then attach that to a hotkey with hs.hotkey.bind() (http://www.hammerspoon.org/docs/hs.hotkey.html#bind)

Cheers,
Chris

--
You received this message because you are subscribed to the Google Groups "Hammerspoon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hammerspoon...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/a89926ba-aae7-4593-8d75-4788b167cd43n%40googlegroups.com.


--
Cheers,

Chris

Joel D Canfield

unread,
Aug 2, 2023, 12:41:20 PM8/2/23
to Hammerspoon
bingo. was working on a hotkey binding but my brain wouldn't serve up the concept of a function to run with that hotkey. even sussed the lack of a sleep/wait function (oh, Lua . . . ) and got that sorted.

thanks ever so much.

Reply all
Reply to author
Forward
0 new messages