2

I have an awesome Pomodoro application, but there are no keyboard shortcuts to start and pause it. I've been trying to code an AppleScript for the past hour, reading the AppleScript reference and searching online, but I'm getting nowhere.

What I want to do is have an AppleScript (it will be launched from an app called BetterTouchTool) click on coordinates on the menu bar, (the Pomodoro app runs in the background and I have all the coordinates needed), a cursor-back needed for the second cursor back (to get back to the initial cursor position), click a second time on the 'Start/Pause' dropdown item (from coordinates), and then do a second cursor-back to have the cursor back to its original position.

EDIT: the application is a timer application (in the menu bar) with a dropdown menu that has as the first item either 'Start', 'Pause' or 'Resume'—which is what I want to be able to click via a keyboard-assigned AppleScript.

EDIT2: got this far:

tell application "System Events" 
    click (click at {1447, 10}) 
end tell 
tell application "System Events" to tell process "Pomodoro Timer" 
    click (click at {1456, 37}) 
end tell

But don't know how to code the cursor back, and I get this error:

System Events got an error: Can’t get menu bar item "00:58" of menu bar 2 of application process "Pomodoro Timer".

Could someone please help me out?

  • What acout cliclick from apple.stackexchange.com/questions/40141/… ? – Mateusz Szlosek Aug 16 '16 at 20:05
  • More complete information about the "Pomodoro application" should have been included in your question. Additionally, if this application runs as a menu extra, then it may be scriptable without the need for an external click type program. However, without additional information about this "Pomodoro application" there's no sense in commenting further. – user3439894 Aug 16 '16 at 20:44
  • My suggestion is to open Script Editor and click Window in the menu bar. Then scroll down and click Library. You will be presented with a list of applications that are currently in the Script Editor Library. If the application you seek is not in this list then you can try clicking the + icon and then navigating to Applications folder where the app is located. Once you have the application selected click open. If the application is scriptable it should be added to the Script Editor Library where you can then read up on how to script it to make it do what you want it to do. – I0_ol Aug 16 '16 at 20:48
  • @user3439894 It's a timer application (in the menu bar) with a dropdown menu that has as the first item either 'Start', 'Pause' or 'Resume'. – samseva Aug 17 '16 at 2:48
  • @user556068 Oh, awesome suggestion. The app isn't scriptable, but Photoshop is. Thanks, that may come in handy. – samseva Aug 17 '16 at 2:54
1

There's a scripting addition called "AppleScript Toolbox" (it's an osax). Get it at https://astoolbox.wordpress.com/

With that, you can simply write:

AST click at {10, 20}

That clicks into the menu bar, for instance, and opens the Apple menu.

If you want to preserve the original cursor position first, use this:

set origPos to AST mouse point location

And to restore it use:

AST set mouse point location origPos
  • Awesome. Using this code makes the mouse cursor click on a dropdown menu, but adding a second 'AST click at {10, 20}' doesn't make the mouse click on the menu item, but it only makes the mouse cursor move over it. What code do I need to initiate a click? – samseva Jan 15 '17 at 0:59
  • You are probably causing a double click, which is not what you want. Try adding a "delay 1" between the clicks. – Thomas Tempelmann Jan 15 '17 at 17:15
  • It's working. Just missing one last thing. What code do you need to make the cursor go back to the original position? – samseva Jan 16 '17 at 22:30
  • Look at the Dictionary of the AST, e.g. using Script Editor. There you'll find similar comments to get and set the mouse position without clicking. Let me know if you can't figure it out. Also, if this answer helped you, please upvote it and accept it as the helpful answer. Also, it might be helpful to others if you add your final solution to your question. – Thomas Tempelmann Jan 17 '17 at 13:21
  • Hi, Thomas. I searched the Script Editor, as well as the AppleScript Language Guide, but couldn't find anything about "cursor back." Right now I have: tell application "System Events" AST click at {808, 13} delay 0.1 AST click at {808, 33} end tell It works, but the cursor ends up where it clicks and you then have to bring back the cursor where it originally was. Would you know where to look for the "cursor back" code (I know it exists, I have seen it on a few occasions :D ) ? – samseva Jan 17 '17 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .