1 2 3 Previous Next 44 Replies Latest reply: Dec 14, 2013 7:38 AM by dickguertin Go to original post
  • 30. Re: Run an applescript at certain time?
    twtwtw Level 5 Level 5 (4,690 points)

    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.

  • 31. Re: Run an applescript at certain time?
    MacMan240 Level 1 Level 1 (80 points)

    Where would an ideal place be to put this script. In the System Library somewhere?

  • 32. Re: Run an applescript at certain time?
    twtwtw Level 5 Level 5 (4,690 points)

    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. 

  • 33. Re: Run an applescript at certain time?
    MacMan240 Level 1 Level 1 (80 points)

    twtwtw wrote:

     

    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.

    I didn't see that, I'll see if I can get the paramendics to put there files in a folder somewhere. They are not very important though.

  • 34. Re: Run an applescript at certain time?
    MacMan240 Level 1 Level 1 (80 points)

    twtwtw wrote:

     

    what exactly are you trying to accomplish with this?  If it's just to keep from deleting files that are being worked on at the moment, a better solution would be this, where you offset deletion by an hour:

     

    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 whose type identifier is "com.adobe.pdf" and creation datelowerLimit and creation date < lowerLimit and name starts with "face_sheet_")

    end tell

     

    This won't touch any files newer than an hour old, but will catch them the next day if they're still there. (I used 2 hours on the lower limit for overlap, so you don't get some weird situation where a file is created exactly on the hour and never gets deleted).

    The script specifies "lowerLimit" twice so I fixed that but it still doesn't work when I run it.

  • 35. Re: Run an applescript at certain time?
    twtwtw Level 5 Level 5 (4,690 points)

    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.)

  • 36. Re: Run an applescript at certain time?
    MacMan240 Level 1 Level 1 (80 points)

    oops, I reversed them, thanks again!

  • 37. Re: Run an applescript at certain time?
    MacMan240 Level 1 Level 1 (80 points)

    New problem, the script is only running on the administrator account, even when I was logged in to the normal user account at the time of the script activation (Admin account was and always will be running in background)

  • 38. Re: Run an applescript at certain time?
    dickguertin Level 1 Level 1 (0 points)

    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?

  • 39. Re: Run an applescript at certain time?
    dickguertin Level 1 Level 1 (0 points)

    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?

  • 40. Re: Run an applescript at certain time?
    twtwtw Level 5 Level 5 (4,690 points)

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

     

    looking at it now...

  • 41. Re: Run an applescript at certain time?
    twtwtw Level 5 Level 5 (4,690 points)

    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>

  • 42. Re: Run an applescript at certain time?
    dickguertin Level 1 Level 1 (0 points)

    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).

  • 43. Re: Run an applescript at certain time?
    twtwtw Level 5 Level 5 (4,690 points)

    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.

  • 44. Re: Run an applescript at certain time?
    dickguertin Level 1 Level 1 (0 points)

    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