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?

klanomath
  • 66,391
  • 9
  • 130
  • 201
samseva
  • 387
  • What acout cliclick from http://apple.stackexchange.com/questions/40141/when-mousekeys-are-on-how-do-i-click-or-move-the-mouse-using-applescript?rq=1 ? – 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 02:48
  • @user556068 Oh, awesome suggestion. The app isn't scriptable, but Photoshop is. Thanks, that may come in handy. – samseva Aug 17 '16 at 02:54
  • @samseva, Is there some good reason why you cannot also provide the fully qualified name of the "Pomodoro application" and where it can be acquired, providing us with a URL? Also, what version of OS X are you running? – user3439894 Aug 17 '16 at 03:12
  • @user3439894 I didn't think it was relevant. Pomodo Timer, Mac App Store. $3; worth it, but missing a keyboard shortcut. Yes, I could contact the developers and ask for this feature to be added, but I thought if someone could point me to an AppleScript resource to correctly code mouse clicks (which I can't seem to find anywhere) would be better. – samseva Aug 17 '16 at 03:20
  • 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". – samseva Aug 17 '16 at 03:25
  • As a test, using "Pomodoro Time" (free) instead of "Pomodoro Timer" ($2.99 USD) and used Accessibility Inspector from Xcode to see what was available to do UI Scripting with. Not liking the abundance of missing values of most of the properties I decided to use cilclick in a do shell script command passing it the appropriate coordinates to click the app on the menu bar, click the start/pause button and back to the original coordinates to hide the menu. E.g. do shell script "cliclick c:1877,11 c:1877,234 c:1832,11", so I'd suggest going that route. – user3439894 Aug 17 '16 at 04:27
  • @user3439894 Thanks for the help. I tried the shell script in Terminal, Script Editor and the app you suggested. I'm not knowledgeable in Shell script. I'm not doing it correctly. Have do you make all this run? – samseva Aug 17 '16 at 04:34

1 Answers1

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 00: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
  • Use the "Open Dictionary..." command from the File menu, then select the AST from the list. Remember that for next time you use the Script Editor. I have updated my answer to add the information you seek. Also, I believe you do not have to use the "tell" command because the AST is not an app but an extension to the internal Applescript commands. – Thomas Tempelmann Jan 18 '17 at 17:30
  • Hi, Thomas. Thank you very much for all of your help! This will be a very useful script for productivity and many other things. Kind regards. – samseva Jan 19 '17 at 13:22