I have one big brain bender for you all.

Here is what I’m trying to do. I have a app that I’m trying to GUI script seeing as it does not have anyway to script it. It’s called SleepLess. Well when I run it, it only is able in the Finder menu bar.

Here what I tried for scripting for it.

tell application "Finder"
	activate
end tell

tell application "System Events"
	tell process "SleepLess"
		click menu item "Turn SleepLess OFF" of menu 1 of menu bar item "SleepLess" of menu bar 1
		click menu item "Turn SleepLess ON" of menu 1 of menu bar item "SleepLess" of menu bar 1
		click menu item "Turn SleepLess OFF" of menu 1 of menu bar item "SleepLess" of menu bar 1
		click menu item "Turn SleepLess ON" of menu 1 of menu bar item "SleepLess" of menu bar 1
	end tell
end tell

Now here is what I get. And I don’t know why. Please help.

click menu item "Turn SleepLess OFF" of menu 1 of menu bar item "SleepLess" of menu bar 1 of process "SleepLess"

Now I know it works because I redid my script to this.

tell application "Finder"
	activate
end tell

tell application "System Events"
	tell process "SleepLess"
		click menu item "Quit SleepLess" of menu 1 of menu bar item "SleepLess" of menu bar 1 of process "SleepLess"

And that script works like it should clicking the menu item to make SleepLess quit.

If anyone out there can find a way to make a GUI applescript that will click the menu item Trun SleepLess OFF then stop for say 5 to 10 seconds then click the menu item Turn SleepLess ON, Then stop for 5 to 10 seconds once more and just repeat that set over one more time. I would jump for joy.

Why I’m trying to do this is this? When SleepLess is runing I can close my PowerBook G3 and have the Laptop still runing with out the screen on. Then when I open the lid the screen comes back on. Well there are times that I need to sleep the mac. When I do Sleep it and then wake it up. All SleepLess will do is keep my PowerBook and screen from sleeping. So if I want to be able to run the mac with the lid closed once more I have to do what I just typed out. I find my self haveing to do this all to often. So I though what not have AppleScript do it for me. Till I tried to script it, it sounded good when I put it down on paper.

Thank you for you time,
Michael

Model: PowerBook 233 Mhz G3, 100 GB Hard Drive with 160 MB of RAM
AppleScript: 1.10.3
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)

I couldn’t even get SleepLess to work for me at all (downloaded, but not registered). Is it only active on registration?
The light bulb appears in the Finder bar, but clicking on it has no effect, and so I cannot replicate those menu views that you mentioned.
However, “SleepLess” appears in the list of processes in System Events, and the following script:

tell application "SleepLess" to activate
tell application "System Events"
	tell process "SleepLess" to tell menu bar 1 to tell menu bar item "SleepLess" to tell menu "Sleepless"
		set n to name of every menu item
	end tell
end tell
return n

returns the list {“About SleepLess”, missing value, “Services”, missing value, “Hide SleepLess”, “Hide Others”, “Show All”, missing value, “Quit SleepLess”}
That would explain why your “Quit SleepLess” menu item works, but it appears that “Turn SleepLess ON / OFF” isn’t listed.

Maybe if you run the above script, you could check that the menu items are listed as you think they are - there may be hidden spaces in the name, if it appears at all for you. All the best,
PJ.

When I run your script something I might have something I’ll post back if it works.

Model: PowerBook 233 Mhz G3, 100 GB Hard Drive with 160 MB of RAM
AppleScript: 1.10.3
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)

:frowning: No go. I could not get it to work.
Maybe can someone can find out how to make this App play nice with AppleScript. What if I tell finder to do the clicking on the items and stop trying to tell SleepLess. From what I can see if I can just find out how and what SleepLess does. I would redo a new App that would only be AppleScriptable but all so make it free.

There are a couple of issues involved here, camgangrel.

The first one is about identifying the correct menu and menu item name. This isn’t quite as easy as it perhaps should be, since SleepLess displays only one menu of several - and identifies the target menu item internally with a different name to those shown in the menu.

SleepLess actually has five menus: Apple, SleepLess, File, Edit and Actions. The first menu item of the latter, Actions (the only visible one menu), is actually SleepLess ON - rather than the displayed names Turn SleepLess ON or Turn SleepLess OFF. (Note that the name remains the same, regardless of status.)

You should be able to confirm most of this by running the following script:

property lf : ASCII character 10
property rtf0 : lf & "\\pard\\tx566\\tx1133\\tx1700\\tx2267\\tx2834\\tx3401\\tx3968\\tx4535\\tx5102\\tx5669\\tx6236\\tx6803\\fi280\\ql\\qnatural\\pardirnatural" & lf
property rtf1 : "{\\rtf1\\mac\\ansicpg10000\\cocoartf824\\cocoasubrtf380" & lf & "\\readonlydoc1{\\fonttbl\\f0\\fswiss\\fcharset77 Helvetica-Bold;\\f1\\fswiss\\fcharset77 Helvetica;}" & lf & "{\\colortbl;\\red255\\green255\\blue255;}" & lf & "\\paperw11900\\paperh16840\\margl1440\\margr1440\\vieww6260\\viewh11860\\viewkind0" & rtf0 & lf & "\\f0\\b\\fs24 \\cf0 \\ul \\ulc0 \\" & rtf0 & "\\cf0 \\ulc0 "
property lst : "\\" & rtf0 & lf & "\\f1\\b0\\fs8 \\cf0 \\ulnone \\" & rtf0 & lf & "\\fs24 \\cf0 	"
property hdr : rtf0 & lf & "\\f0\\b \\cf0 \\ul "

to write_data from d to f
	set r to open for access f with write permission
	set eof r to 0
	write d to r
	close access r
end write_data

to show_menu_summary for p
	launch application p
	set text item delimiters to "\\" & lf & tab
	tell application "System Events"
		tell (get menu bar items of menu bar 1 of process p) to set {s, l} to {item 1, rest}
		repeat with i in l
			tell i to set contents to hdr & name & lst & name of menu 1's menu items
		end repeat
		tell s to set l to {name & "\\" & rtf0 & lf & "\\f1\\b0\\fs8 \\cf0 \\ulnone \\" & lf & lf & ¬
			"\\fs24 	" & name of menu 1's menu items} & l
	end tell
	set text item delimiters to "\\" & lf & "\\"
	repeat with d in {{"missing value", "---------------"}, {".", "\\'c9"}}
		set {l, text item delimiters} to {l as text, d's item 1}
		set {l, text item delimiters} to {l's text items, d's item 2}
	end repeat
	set {l, text item delimiters} to {(l as text) & "\\" & lf & "}", {""}}
	set f to choose file name default name p & " Menu Summary.rtf" with prompt ¬
		"Confirm the menu summary file name and location:" default location path to desktop
	write_data from rtf1 & l to f
	tell application "Finder" to open f
end show_menu_summary

show_menu_summary for "SleepLess"

So, in a perfect world, the following should work:

tell application "System Events" to click menu item "SleepLess ON" of menu "Actions" of ¬
	menu bar item "Actions" of menu bar 1 of application process "SleepLess"

Unfortunately, although using the correct target now avoids the old “NSReceiverEvaluationScriptError: 4” error, it still doesn’t have the desired effect - which brings us to the second issue. Clicks and other actions just don’t register (possibly due in part to SleepLess being a background-only application).

The only option here seems to be a brute-force workaround, using something like Extra Suites. The following works fairly well here:

Requires Extra Suites

to toggle_SleepLess_status()
	tell application "System Events" to set p to {(item 1 of (get position of ¬
		menu bar 1 of application process "SystemUIServer")) - 11, 11}
	tell application "Extra Suites"
		set l to ES mouse location
		ES move mouse p
		ES click mouse
		ES move mouse l
		delay 0.2
		ES type string "t" & return
	end tell
end toggle_SleepLess_status

repeat 4 times
	toggle_SleepLess_status()
	delay 5
end repeat