I have one big brain bender for you all. When it comes to Applescript.

camgangrel21

Mac Programer
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 able to be 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.

tell application "Finder"
activate
end tell
tell application "System Events"
click menu item "Turn SleepLess OFF" of menu 1 of menu bar item "SleepLess" of menu bar 1 of process "SleepLess"
"System Events got an error: NSReceiverEvaluationScriptError: 4"

Now I know it works because just for S&Gs 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 put down on paper.
Thank you for you time,
Michael
 
Well, I see one problem, but it doesn't lead me to a solution. But maybe you'll be able to take what I found further.

"menu 1" is not the SleepLess menu extra you see in the menu bar. It's SleepLess's application menu (which is invisible). If you try this:

set x to the menu bar 1 of application process "SleepLess"
return the name of every menu of x

You'll see that SleepLess has many menus. I think the relevant one is "Actions", but...I don't see the a "Turn SleepLess ON" item in that menu. I see a "SleepLess ON" item, but I can't figure out how to use it. Try this to see all the items:

get menu bar 1 of application process "SleepLess"
get menu "Actions" of the result
return the name of every menu item of the result

I ran some tests with the Finder, and it seems that I can't get it to open a new Finder window by manipulating its menu unless it is the frontmost app. Since SleepLess obviously can't become the frontmost app, this could be a problem. More testing needs to be done to say for certain, though.
 
Thank you for that. I have been trying to look at what happens when I click on the Turn SleepLess OFF menu item. Then what it is doing when I click on Turn SleepLess ON in console here is what I found loged.

____
kextunload: unload kext /Applications/SleepLess 2.2.1/SleepLess.app/Contents/Resources/Insomnia.kext succeeded --> This is what happens when I clicked SleepLess's Turn SleepLess OFF menu item.
kextload: /Applications/SleepLess 2.2.1/SleepLess.app/Contents/Resources/Insomnia.kext loaded successfully -->This is what happens when I clicked SleepLess's Trun SleepLess ON menu item.
kextunload: unload kext /Applications/SleepLess 2.2.1/SleepLess.app/Contents/Resources/Insomnia.kext succeeded --> This is what happens when I clicked SleepLess's Turn SleepLess OFF menu item.
kextload: /Applications/SleepLess 2.2.1/SleepLess.app/Contents/Resources/Insomnia.kext loaded successfully -->This is what happens when I clicked SleepLess's Trun SleepLess ON menu item.
kextunload: unload kext /Applications/SleepLess 2.2.1/SleepLess.app/Contents/Resources/Insomnia.kext succeeded --> This is what happens when I clicked SleepLess's Turn SleepLess OFF menu item.
kextload: /Applications/SleepLess 2.2.1/SleepLess.app/Contents/Resources/Insomnia.kext loaded successfully -->This is what happens when I clicked SleepLess's Trun SleepLess ON menu item.
_____
Now what is makeing me go nuts is how badly this app is put together. This looks more like a high school progaming thing. What chaps my back side is that I payed for this "Thing".
Now do you think I might just do with apple script that SleepLess is doing. Having Apple Script to copy and delete that one file that seams to be what makes all the Voodoo that SleepLess do?
Thank you for your help and time.
If I can find out how to get this thing working right I just might make a App that does what SleepLess does but for free.
 
I think you're being harsh on SleepLess. It looks like that kext (kernel extension) it's loading/unloading is part of SleepLess, and kernel extensions are not easy things to make!

But yes, I think you could mimic the functionality of the menu item by loading/unloading SleepLess's kext yourself. I've loaded kexts like this from Terminal before.

Open Terminal and try entering this:

kextload "/Applications/SleepLess 2.2.1/SleepLess.app/Contents/Resources/Insomnia.kext"

Hite return, and enter your password when prompted. If it works, you can unload it the same way, only using kextunload instead of kextload.

You can do this same thing through AppleScript by saying:

do shell script "kextload \"/Applications/SleepLess 2.2.1/SleepLess.app/Contents/Resources/Insomnia.kext\""

I haven't tested this with SleepLess, though, so...try this at your own risk. You might want to enter "man kextload" in Terminal for more info on the kextload command and how to use it. There are a lot of options in there that I'm not familiar with.
 
Thank you for that feed back Mikuro. I will try to do that. As for what I had to say about SleepLess, was because it reminds me of how any body if thay want to make a $ off of Windows users. Would and still do make half backed apps that run. But damn if does not trash you hard drive and your reg in windows. That makes the system come to the point that you have to reinstall windows. Loseing every thing that was not backed up. That was the point I was trying to make. The way that SleepLess is put together and acts it to me fells more like a POS App that should have benn made for Windows not the mac.
 
Back
Top