Wait in applescript.

Joined
Jan 4, 2011
Messages
1
Reaction score
0
Points
1
I am trying to make a simple AppleScript application in Xcode. I want it to set the computer to sleep after 30 minutes. My code looks like this:

script musicAppDelegate
property parent : class "NSObject"

on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened

tell the application "Finder" to sleep

end applicationWillFinishLaunching_

on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_

end script

It works, but how do i make the delay?

Jonas.
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
I beleive the Applescript delay command still works in ApplescriptObjC projects, like this.

Code:
delay (30)  --delays code execution for thirty seconds

Regards Mark
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
The delay function's parameter is the number of seconds, not minutes. So, you'll want delay set to 1800.
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
vansmith is right, the delay setting is in seconds and not minutes, I read your posting wrong.

The other alternative is to create your own timer with the NSTimer class, but that will be a bit more involved, so see how you get on with the delay command first.

Regards Mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top