Scripting menu extra app - Nocturne

I have spent the last two days doing my research here and elsewhere. I have been though dozens of posts regarding UI scripting of menu extra apps in the menubar and have tested many of the scripts and come across the same hurdles as others. And try as I might I have not managed to find a solution.

The app I am trying o automate is Nocturne, which I thought would be fairly simple. It seems that SystemUIServer only affects those menu extras that Apple wrote, and without AXDescription I have nothing else unique about the app that AppleScript is willing to latch onto.

I have also opened the nib in interface builder in hopes of finding some hidden hot keys that I could make use of, but admittedly I was a bit out of my element there.

All I am hoping to do is launch the application, toggle the 1st menu item and carry on about my business. I never imagined it would be so difficult script for menu extras. Should I be trying this in Shell instead?

Here is what I have so far, which clearly wouldn’t work, but it’s all I can come up with.

launch application "Nocturne"
tell application "System Events"
	tell process "Nocturne"
		click menu item 1 of menu 1 of menu bar 1
	end tell
end tell

Anyhow, thanks for any help you can offer. Much appreciated.

Model: Mac Pro
AppleScript: 2.3
Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Since the item resides in your menu bar, a better solution (unless your menu bar items keep affecting the position of “Nocturne” icon) would be to use
clilick: http://www.bluem.net/en/mac/cliclick/

“Cliclick” is short for “Command-Line Interface Click”. It is a a tiny shell / Terminal application that will emulate mouse clicks or series of mouse clicks (including doubleclicks and control-clicks) at arbitrary screen coordinates.

Unfortunately Nocturne will rarely be in the same place so this won’t help. Pretty cool tool though.

then use “if” statements to check if particular process is running and then make clilick click different co-ordinates.

If you add Nocturne to your “launch on start-up” items then the position is less likely to change

Because of the nature of what I do I am constantly rotating the apps in my Dock and the apps in the menu bar. This is why I am trying to script the ones that I just need on occasion. i don’t have to assign them any permanent real-estate and just toggle them with a hot key when needed on a whim.

To be honest it’s not a make or break deal, it’s just something that I’ve identified in my workflow as needing to change. Just wish I could.

When I launch, Nocturne, it starts in “night” mode (if i had quit it when it was in night mode).

Nocturne’s “Switch to Day” mode is same as normal screen. So quitting Nocturne, turns night mode off and returns normal mode.

Also, i find that if Nocturne is already running, and I launch Nocturne again the mode is changed.

I don’t see a need for a script.

Sometimes it just takes another set of eyes and a new perspective to see the obvious solutions. Brilliant! Thank you so much for seeing this. I couldn’t see the forest for the trees on this one, lol.

So based on Chris2’s findings I wrote the following script to test if the app is running. If it isn’t, the script will launch the app and “Night” mode will be on. If the app is running already then the script will quit the app and “day” mode will return. So simple, I can’t believe I didn’t see this earlier.

Thanks again Chris2 for seeing the obvious. still hanging my head in shame

if appIsRunning("Nocturne") then
	tell application "Nocturne" to quit
else
	tell application "Nocturne" to activate
end if

on appIsRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end appIsRunning
So simple, I can't believe I didn't see this earlier. Thanks again Chris2 for seeing the obvious. 

You are welcome!! It happens with everyone, and especially with those who know a lot.