Results 1 to 4 of 4
  1. #1

    Member Since
    Jan 04, 2011
    Wait in applescript.
    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?


  2. #2

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    West Sussex, UK
    I beleive the Applescript delay command still works in ApplescriptObjC projects, like this.

    delay (30)  --delays code execution for thirty seconds
    Regards Mark

  3. #3

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    2012 13" MBP (2.5 i5, 8GB)
    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
    Writing a Quality Post

  4. #4

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    West Sussex, UK
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Wait, wait, wait, crash...on boot.
    By ohmandd in forum OS X - Operating System
    Replies: 6
    Last Post: 12-15-2011, 11:15 AM
  2. To wait, or not to wait? That is the question...
    By ogacon in forum Switcher Hangout
    Replies: 9
    Last Post: 03-21-2008, 02:20 PM
  3. Purchasing: To wait or not to wait
    By mac2k in forum Apple Desktops
    Replies: 3
    Last Post: 08-29-2007, 12:07 AM
  4. MacBook Pro - To wait or not to wait?
    By Spicky in forum Apple Notebooks
    Replies: 29
    Last Post: 05-15-2006, 01:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts