New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Wait in applescript.


Post Reply New Thread Subscribe

 
Thread Tools
paradisgutten

 
Member Since: Jan 04, 2011
Posts: 1
paradisgutten is on a distinguished road

paradisgutten is offline
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:

Quote:
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.
QUOTE Thanks
Mark FX

 
Mark FX's Avatar
 
Member Since: Aug 13, 2011
Location: West Sussex, UK
Posts: 167
Mark FX has a spectacular aura about

Mark FX is offline
I beleive the Applescript delay command still works in ApplescriptObjC projects, like this.

Code:
delay (30)  --delays code execution for thirty seconds
Regards Mark
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 17,684
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
The delay function's parameter is the number of seconds, not minutes. So, you'll want delay set to 1800.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Personal Twitter
QUOTE Thanks
Mark FX

 
Mark FX's Avatar
 
Member Since: Aug 13, 2011
Location: West Sussex, UK
Posts: 167
Mark FX has a spectacular aura about

Mark FX is offline
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
QUOTE Thanks

Post Reply New Thread Subscribe


« X code 3.2 | To the Core »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Glad I didn't wait for Lion halfmonkey OS X - Operating System 5 05-24-2011 09:15 AM
Switching for productivity Vroomer Switcher Hangout 15 06-21-2010 01:39 AM
should i wait.... bigmof Switcher Hangout 1 03-26-2007 07:14 PM
To wait, or not to wait macpwns Apple Notebooks 2 06-09-2006 03:47 PM

All times are GMT -4. The time now is 05:24 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?