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

    Here's the eternal help-desk misunderstanding.  You don't know how to approach the problem but have all sorts of information about what your specific problem is.  We know how to approach problems like this, but have very little information about your specific needs.  Help occurs when we bridge that gap. 

     

    We need to know things like the following:

    • what folder do you want things deleted from?
    • what kinds of files are the files to be deleted (extension, file type, uti, or etc)?
    • what pattern of file names do you want deleted (prefixes, suffixes, keywords, or etc)?

    Don't be shy about spelling things out in detail; we like that!

  • 16. Re: Run an applescript at certain time?
    MacMan240 Level 1 Level 1 (80 points)
    1. The folder  being deleted from is the desktop
    2. They are pdf files with .pdf extension
    3. As far as the prefixes and keywords, the files will either be in  order of 001.pdf, 002.pdf etc; or I can set the scanner so that the file names are the date and time the files were scanned. (ex 20130219051258.pdf)
  • 17. Re: Run an applescript at certain time?
    twtwtw Level 5 Level 5 (4,690 points)

    so do you want to delete all pdf files from the desktop, or just pdf files with a numeric name?

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

    Numerical name only please, the paramedics also have instructional pdfs on the desktop as well.

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

    since you have control of the scanner, can you add an identifying label to the name?  If the file names were something like "Temporary Scan 001.pdf" that would make life easier.

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

    I am not sure, I will have to get back to you on that.

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

    Eh, never mind, I think this will work:

     

    tell application "System Events"

      -- find all pdf files that were created in the last 24 hours

              set questionableFiles to files of desktop folder whose type identifier is "com.adobe.pdf" and creation date > ((current date) - 1 * days)

      -- loop through files, deleting files whose name is all numbers

              repeat with thisFile in questionableFiles

                        set mainName to text 1 thru -5 of (get name of thisFile)

                        try

      -- if the file name has any non-numbers, this will throw an error and skip the delete

                                  mainName as integer

                                  delete thisFile

                        end try

              end repeat

    end tell


    save this as a script file somewhere convenient, then change the plist I gave above to read as follows (all that's changed is the ProgramArguments key, which now will point to an external file rather than build the script internally):

     

    <?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.delete.daily</string>

              <key>ProgramArguments</key>

              <array>

                        <string>osascript</string>

                        <string>/path/to/script file.scpt</string>

              </array>

              <key>StartCalendarInterval</key>

              <dict>

                        <key>Hour</key>

                        <integer>0</integer>

                        <key>Minute</key>

                        <integer>0</integer>

              </dict>

    </dict>

    </plist>

  • 22. Re: Run an applescript at certain time?
    Frank Caggiano Level 7 Level 7 (23,795 points)

    MacMan240 wrote:

     

    Numerical name only please, the paramedics also have instructional pdfs on the desktop as well.

    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. At some point some or all of the instructional pdfs will get clobbered.

     

    Why not at least set up two folders one for the instructional pdfs and one for the temporary ones. It will make your life a lot easier in the long run.

  • 23. Re: Run an applescript at certain time?
    Frank Caggiano Level 7 Level 7 (23,795 points)

    - find all pdf files that were created in the last 24 hours

    Shouldn't you be looking for files older than a given time.

     

    If you get all files created in the last 24 hours what happens if a EMT loads a file right before this runs and it hasn;t been used yet?

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

    twtwtw wrote:

     

    since you have control of the scanner, can you add an identifying label to the name?  If the file names were something like "Temporary Scan 001.pdf" that would make life easier.

    all scans will now have a prefix "face_sheet_" followed by a serial "001, 002, 003, etc" to make "face_sheet_001.pdf, face_sheet_002.pdf, face_sheet_003.pdf, etc"

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

    ok, then you can simplify the script I gave above to read so:

     

    tell application "System Events"

      -- find all pdf files that were created in the last 24 hours that start with face_sheet

              delete (files of desktop folder whose type identifier is "com.adobe.pdf" and creation date > ((current date) - 1 * days) and name starts with "face_sheet_")

    end tell

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

    Thank you sooo much!! I know I can be a pain to work with sometimes but you sought me throught this. One last question though. I want the script to restart as pecified as below in red and confirm the the script will end where specified as well:

     

    Screen Shot 2013-02-20 at 5.08.47 PM.png

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

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

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

    Thinking about overlaps, I should point out that if the computer happens to be off or asleep at midnight, the script will run the next time the computer's activated.  However, it only looks back a day and 2 hours; if the machine isn't reactivated until (say) 6am there's a four hour window where the script might miss files.  Probably not an issue, but...

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

    Thank you!!