Applescript shell call failing from cron (only)

Discussion in 'Mac Programming' started by babbler, Oct 10, 2007.

  1. babbler macrumors member

    Joined:
    Apr 15, 2006
    #1
    I have an applescript which contains the line:

    -- runs the command system_profiler and grabs the relevant result line
    set AirPort to (do shell script "system_profiler |grep 'Current Wireless Network:'").

    It works perfectly when run directly from the script editor and when exported as an app. I put it into cron (via cronnix) and when cron tries to run it, it fails with a message roughly "could not find command system_profiler". If I run it from cronixx - by choosing 'run now' again it works perfectly.

    [​IMG]

    Any ideas why cron cannot run the shell script.

    Thanks

    (Incidentally, the purpose of the line is to find out where the macbook is and run a backup if it is in the office, but not elsewhere. It is a slightly sledgehammer approach to finding which wireless network I am attached to, any better ideas ?)
     
  2. MongoTheGeek macrumors 68040

    MongoTheGeek

    Joined:
    Sep 13, 2003
    Location:
    Its not so much where you are as when you are.
    #2
    When its run by cron its run in a different user's process. The paths aren't initialized in the same way.

    try this
    set AirPort to (do shell script "/usr/sbin/system_profiler |grep 'Current Wireless Network:'").
     
  3. babbler thread starter macrumors member

    Joined:
    Apr 15, 2006
    #3
    Thanks. That did it.

    I thought it must be a problem with the path to system_profiler, but I could not find it. Searching for system_profiler in Finder does not locate it. How could/should I have found it?


    Thanks again
     
  4. MongoTheGeek macrumors 68040

    MongoTheGeek

    Joined:
    Sep 13, 2003
    Location:
    Its not so much where you are as when you are.
    #4

    in terminal

    $ which system_profiler
    /usr/sbin/system_profiler
     

Share This Page