Skip navigation

Run an applescript at certain time?

6782 Views 44 Replies Latest reply: Dec 14, 2013 7:38 AM by dickguertin RSS
  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    Feb 20, 2013 2:30 PM (in response to Frank Caggiano)

    Frank Caggiano wrote:

     

    Oh man you really need to take a step back and set this up in a more sane manner. Having both temporary files and permanent files in the same folder (and having that folder be the Desktop) with the same file extension is not a good thing.

     

    Frank has a good point here.  You might want to take this advice to heart.

  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    Feb 20, 2013 2:34 PM (in response to MacMan240)

    No.  /System/Library/ is for Apple's use only.  Don't go there without a very good reason (which almost no one has).  I'd put it in /Library/Scripts, assuming you're running it as an administrator. 

  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    Feb 20, 2013 3:08 PM (in response to MacMan240)

    Did you modify it like this?  this works fine on my machine:

     

    tell application "System Events"

      -- find all pdf files that were created between 1 hour and 26 hours ago that start with face_sheet

              set lowerLimit to ((current date) - 1 * days - 2 * hours)

              set upperLimit to ((current date) - 1 * hours)

              delete (files of desktop folder of user domain whose type identifier is "com.adobe.pdf" and creation datelowerLimit and creation date < upperLimit and name starts with "face_sheet_")

    end tell

     

    If that's not working then start looking for fiddly issues: make sure the files are in the correct date range, and that the file name prefix is exactly as spelled in the script (looking for missing or extra spaces, underscores, punctuation, capitalization, etc.)

  • dickguertin Level 1 Level 1 (0 points)
    Currently Being Moderated
    Dec 13, 2013 4:20 PM (in response to MacMan240)

    I have read through this posting carefully, and I'd like to use "launchd" with a driver.plist to run a compiled Applescript saved in /Applications/myProgram.app, but the Applescript is of the "on run argv" through "end run", and I'd like to pass an argument to myProgram. How can I do that?

     

    I can't figure out what to put in the driver.plist file that would pass an argument to myProgram. I also don't know how to "silence" the process ... that is, do something equivalent to >/dev/null 2>&1 to block output/errors.

     

    From a crontab entry, I can execute a .bash script (Darwin), and do:

     

    osascript /Applications/myProgram.app parm >/dev/null 2>&1

     

    But what I've found is that Snow Leopard balks at this for some reason, and I get email from the cron daemon saying commands are unrecognozed. I've read that this could be caused by the lack of a WindowServer when cron is running and I'm logged onto the computer remotely and don't have a "window" on the target machine. Any suggestions?

  • dickguertin Level 1 Level 1 (0 points)
    Currently Being Moderated
    Dec 13, 2013 4:24 PM (in response to twtwtw)

    twtwtw, I recently replied to this thread with a question about using "launchd" and "on run argv" types of Applescripts where I want to pass a parameter to the Applescript. Could you look at that, and respond?

  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    Dec 13, 2013 6:29 PM (in response to dickguertin)

    hmmm...  If I hadn't seen that post, what makes you think I would have seen this one?

     

    looking at it now...

  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    Dec 13, 2013 6:48 PM (in response to dickguertin)

    With osascript you just tack any parameters on at the very end; translated to launchd that means adding a separate string value line for each parameter. re output, launchd has keywords for redirecting standard out and standard error, so just add those in with /dev/null as the value.

     

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

    <plist version="1.0">

    <dict>

              <key>Label</key>

              <string>user.program.driver</string>

              <key>ProgramArguments</key>

              <array>

                        <string>osascript</string>

                        <string>/Applications/myProgram.app</string>

                        <string>parameter 1</string>

                        <string>parameter 2</string>

                        <string>...</string>

              </array>

              <key>StartCalendarInterval</key>

              <dict>

                        <key>Hour</key>

                        <integer>0</integer>

                        <key>Minute</key>

                        <integer>0</integer>

              </dict>

              <key>StandardOutPath</key>

              <string>/dev/null</string>

              <key>StandardErrorPath</key>

              <string>/dev/null</string>

    </dict>

    </plist>

  • dickguertin Level 1 Level 1 (0 points)
    Currently Being Moderated
    Dec 13, 2013 8:56 PM (in response to twtwtw)

    Sorry, I meant to say:  YOU recently replied to this thread, and I have a question about using "launchd" and "on run argv" .... etc.

     

    As for your second reply, with the plist example, I just figured that out from "BPSystemStartup.pdf". However, it doesn't appear launchd will work for me for several reasons, mainly the inability for "display dialog" unless a user is requesting the daemon. In my case, it's being requested via remote login, and there's no WindowServer, therefore UI actions are prohibited. "cron" jobs only work either in Tiger or Leopard. In Snow Leopard, I can only drive bash-scripts, and there, they too have to avoid UI.

     

    Thanks for your prompt reply. I appreciate it very much. I'll survive with what I've got working, and won't resort to daemons or agents via launchclt (launchd).

  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    Dec 13, 2013 11:17 PM (in response to dickguertin)

    I am he as you are he as you are me and we are all together...

     

    This is why it's usually better to start a new thread.

     

    I am confused about why you're trying to use display dialog remotely. launchd is meant for machine-local tasks: if you want to automae something on a remote mac you should use its launchd. Maybe if you explained your goals more I could be more helpful, but if you're going to do that, definitely start a new thread.

  • dickguertin Level 1 Level 1 (0 points)
    Currently Being Moderated
    Dec 14, 2013 7:38 AM (in response to twtwtw)

    Agreed, I'll do thatas soon as I can formulate "the question". I'm thinking it should be: "How can a remotely launched Applecsript display dialog?" I'll cover the details in the original posting. Thanks for your help.

1 2 3 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (3)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.