Apple Script Help

Hi,
  I wrote the below script to delete files of a particular folder, but now I want to do that to the Documents folder. I tried using this script but it didn't work. Any ideas? Or any entirely different script that might work. Thanks.
tell application "Finder"
  display dialog "All files in the documents folder will be deleted at log out. Are you sure you want to continue?"
  try
  delete (every item of folder "Test Folder")
  end try
  empty trash
end tell

Would /User/Account1/Documents work for the path?
No. slash-delimited paths are the standard in UNIX, but the FInder doesn't like them. It prefers colon-delimited paths, or you can use POSIX file to coerce between the two, so either:
      every file of folder "Macintosh HD:Users:Account1:Documents"
or
      every file of folder (POSIX file "/Users/Account1/Documents/")
But you're now hard-coding the script to a specific folder. The 'path to' command that tw talks about will dynamically locate the current user's Documents folder, no matter where it is, or what the user name is.
Or assuming that the account is "Account1" what would.
Again, if you use 'path to', you don't have to care about what the current username/account is, AppleScript will work it out for you.
Also do i need to change the "user domain" part?
Some special folders (such as 'Library') exist at multiple levels - there's a system-level 'Library' folder as well as a user-specific 'Library' folder. Adding this parameter makes sure you get the one you want/expect. It isn't critical in this case since there are no 'documents' folders other than the user level, but it's a good habit to use.

Similar Messages

  • APPLE SCRIPT HELP! Simple Renaming Script

    I dont have any experience with apple script but desperately needed this for a work issue. I basically have tons of files with all the same type of name and need to send the first two numbers in the file to the end of the file as a suffix... so this...
    01 alexa_02.mp3
    needs to turn into this
    01 alexa_02_01.mp3
    So the function is take the first two characters from the file name of all the files in the folder and rename them with a suffix. Here is what I have so far.
    PLEASE HELP! Im desperate!
    [CODE]try
        tell application "Finder" to set the source_folder to (choose folder with prompt "Pick the folder containing the files to rename:") as alias
    end try
    display dialog "Change Suffix to First Two Characters of File Name:" buttons {"Send The Pids!", "Cancel"}
    set the button_pressed to the button returned of the result
    set the item_list to list folder source_folder without invisibles
    set source_folder to source_folder as string
    repeat with i from 1 to number of items in the item_list
        set this_item to item i of the item_list
        set this_item to (source_folder & this_item) as alias
        set this_info to info for this_item
        set the current_name to the name of this_info
        tell application "Finder"
            if the button_pressed is "Send The Pids!" then
                set the filename to the (current_name & the characters 1 thru 2 of current_name) as string
                set orig to quoted form of POSIX path of current_name
                set dest to source_folder & filename
                try
                    set y to dest as alias
                on error
                    set dest to quoted form of POSIX path of dest
                    set command to "mv " & orig & " " & dest
                    do shell script command
                end try
            end if
        end tell
    end repeat[/CODE]

    Made a short script on my own... normally you could do this using the Finder and run a recursive algorythm, but if you just use find to find all files in a folder that ft your criteria and use these links to generate a list of aliases (posix files) it is way faster and acomplished with less code :-)
    set myfolder to characters 1 through -2 of (POSIX path of ((choose folder) as alias)) as text
    set foundfiles to every paragraph of (do shell script "find " & quoted form of myfolder & " -type f -iname \"*.mp3\"")
    repeat with afile in foundfiles
    set afile to ((afile as text) as POSIX file as alias)
    tell application "Finder"
    set filename to name of afile
    set filesuffix to (characters -4 through -1 of filename) as text
    set addonsuffix to characters 1 through 2 of filename
    set filename to (characters 1 through -5 of filename) as text
    set newfilename to filename & "_" & addonsuffix & filesuffix
    set name of afile to newfilename
    end tell
    end repeat

  • Auto refresh with apple script- help please

    can any one help me please
    i use multiple windows in safari at one time and can any one help me to refresh these pages (two windows) automatically using apple script.
    also if I click manually to refresh these pages i get the following note"
    "To open this page again, Safari must resend the form you completed to open the page the first time. This may cause the website to repeat actions it took the first time you sent the form."
    and i have click send for this to happen
    any help from you all will be appreciated as this will help me a lot with the present work that i am doing

    Not sure about the "automatic" reload - Opera allows you to set a refresh time interval for each tab, but not Safari. Also, Safari Extender gives you a single click contextual menu option to "reload all tabs".
    here is an AppleScript for a one-page auto reload. You might be able to alter the script to auto reload all open tabs.
    Not sure about the "warning" message. Can you post a URL so I can have a look?

  • Automator or Apple Script help needed

    Hello,
    I have been trying time and time again to create an automated task that runs every hour, in which it should
    1) Open Web Browser (Safari, Firefox, whichever one)
    2) Type in a URL or choose a bookmark.
    3) Log In to university account, I guess by typing my user and password
    4) Click a bunch of links
    5) Take a screenshot and number it picture_i+1 (where i is the number of the last screenshot taken)
    6) Exit Safari
    7) Mail me picture or keep it on desktop (whichever one doesn't make a difference)
    Now is this possible? Whenever I do it with automator watch me do ( Accessibility options are checked)
    It keeps messing up, it speeds up the process and messes up everything, I went as far as having a text file that has the user name and password, and automator copy's one by one and pastes it in.
    Let me know if anybody has any ideas I would really appreciate it!
    Thank you!

    *So this is what I came up with.... Works perfectly, thanks for your guy's advice....*
    *Now to figure out how to get it to run every hour.*
    CODE:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFEE80;
    overflow: auto;"
    tell application "Safari"
    open location "http://www.blackboard.XXX.edu"
    end tell
    tell application "System Events"
    if UI elements enabled then
    tell process "Safari"
    set frontmost to true
    end tell
    delay 9
    keystroke "u"
    delay 3
    keystroke "s"
    delay 3
    keystroke "e"
    delay 3
    keystroke "r"
    delay 3
    keystroke "n"
    delay 3
    keystroke "a"
    delay 3
    keystroke "m"
    delay 3
    keystroke "e"
    delay 3
    key down tab
    delay 3
    keystroke "p"
    delay 3
    keystroke "a"
    delay 3
    keystroke "s"
    delay 3
    keystroke "s"
    delay 3
    keystroke "w"
    delay 3
    keystroke "o"
    delay 3
    keystroke "r"
    delay 3
    keystroke "d"
    delay 3
    key down return
    else
    tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.universalaccess"
    display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
    end tell
    end if
    end tell
    tell application "Safari"
    activate
    tell application "System Events"
    tell application process "Safari"
    delay 5
    open location "https://www.blackboard.XXX.edu/webapps/blackboard/execute/launcher?>type=StudentCoursesView&id=XXXXXX&url="
    delay 5
    keystroke "p" using command down
    repeat until sheet 1 of window 1 exists
    end repeat
    click menu button "PDF" of sheet 1 of window 1
    delay 3
    click menu item "Save PDF to Web Receipts Folder" of menu 1 of menu button "PDF" of sheet 1 of window 1
    delay 5
    keystroke return
    delay 5
    end tell
    end tell
    end tell
    tell application "Safari"
    activate
    tell application "System Events"
    tell application process "Safari"
    delay 7
    open location "https://www.blackboard.XXX.edu/webapps/blackboard/execute/launcher?>type=StudentCoursesView&id=XXXXXX&url="
    delay 5
    keystroke "p" using command down
    repeat until sheet 1 of window 1 exists
    end repeat
    click menu button "PDF" of sheet 1 of window 1
    delay 3
    click menu item "Save PDF to Web Receipts Folder" of menu 1 of menu button "PDF" of sheet 1 of window 1
    delay 5
    keystroke return
    end tell
    end tell
    end tell
    tell application "Safari"
    activate
    close every window
    quit
    end tell
    </pre>

  • Apple Script Help please

    Pleasewrite an AppleScript for the following scenario: You need to ping the address10.32.8.151 every 5 seconds and report to the current logged in user via adialog box and email a set address when the IP has failed to respond to morethen 6 pings or 30 seconds. Upon failure of the 6 ping test please have thescript run a trace route and export it to a file named tracereport.txt on~/Desktop

    This sounds remarkably like a homework assignment to me...
    I'm guessing something like this covers most of your points.
    property theAddress : "10.32.8.151"
    global missedPings
    on run
              set missedPings to 0 -- initialize the counter
    end run
    on idle
              try
                        do shell script "/sbin/ping -c 1 -t 1 " & theAddress
              on error
                        set missedPings to missedPings + 1
                        if missedPings = 6 then
      networkDown()
                                  tell me to quit
                        end if
              end try
              return 5
    end idle
    on networkDown()
              do shell script "/usr/sbin/traceroute " & theAddress & " &> " & quoted form of POSIX path of ((path to desktop as text) & "tracereport.txt") & " &"
              do shell script "/bin/echo 'Network missed 6 pings' | /usr/bin/mail -s 'Network down' [email protected]"
      display alert "Oops. Network failure" giving up after 5
    end networkDown

  • Help creating apple script to create folder and set access levels

    I'm trying to create folders in FileMaker Pro using apple script and need some help in setting the access level for the folders.  I want to set both Staff and everyone to Read and Write access.   Secondly I would like to have a function key set on the desktop to create new folders and set that same access level.  The default access is Read and I can not find a way to change that.
    Thanks

    I'm trying to create folders in FileMaker Pro using apple script and need some help in setting the access level for the folders.  I want to set both Staff and everyone to Read and Write access.   Secondly I would like to have a function key set on the desktop to create new folders and set that same access level.  The default access is Read and I can not find a way to change that.
    Thanks

  • Please help!! Using Apple Script in Automator for Quicktime

    I would like to add some metadata to a batch of quicktime movies and then make the files unable to be altered and re-saved so that I can post them on the web. If I open a movie in quicktime and run the following apple script I can then perform save as of movie A into movie B and movie B cannot be altered.
    tell application "QuickTime Player"
    set saveable of movie 1 to false
    -- save self contained
    end tell
    I would love to be able to do this on a batch level in automator however I cannot figure out how to pass automator items to the apple script so that their saveable can be set to false, and after this I cannot figure out how to have to movies re-saved so the changes will take effect.
    Any help at all would be greatly appreciated.

    how are you passing files to apple script? as finder items?
    the following should work then
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on run {input, parameters}
    tell application "Finder"
    repeat with cur_file in input
    set fname to (name of (get info for cur_file) as text)
    tell application "QuickTime Player"
    open file (cur_file as text)
    set saveable of document 1 to false
    tell application "Finder" to set new_item to (path to desktop as string) & fname
    save self contained document 1 in new_item
    delay 1
    close document 1
    end tell
    end repeat
    end tell
    end run
    </pre>
    the above will dump the modified files onto your desktop and give them the same names they had before. You can adjust that as you like of course.

  • Help Needed with Apple Script

    I need a little help with Apple Script. I have been using a script for several months now, and all of a sudden it just stopped working. Here's the script"
    ============
    with timeout of 9999 seconds
    tell application "Finder"
    activate
    (* copy target file to another disk - to create a backup *)
    duplicate file "Daily.dmg" of folder "File Backups" of disk "HD Mirror" to folder "Data Backup-Daily" of disk "MacHD 1" replacing yes
    (* copy a 2nd target file to another disk - to create a backup *)
    duplicate file "Personal.dmg" of folder "File Backups" of disk "HD Mirror" to folder "Data Backup-Daily" of disk "MacHD 1" replacing yes
    (* now copy the 2nd target file to my iDisk *)
    duplicate file "Personal.dmg" of folder "Data Backup-Daily" of disk "MacHD 1" to folder "Documents" of disk "xxxxxx" replacing yes
    end tell
    end timeout
    ============
    In the above script, xxxxxx represents the name of my iDisk that is mounted in the Finder.
    Here's my issue - the above script worked fine until just recently. However, now the first two steps work fine, but I get this error message while trying to copy the file to my iDisk:
    "The operation could not be completed because some items had to be skipped. 'Personal.dmg'"
    Does anyone have any ideas on how I can fix this? I'm wondering if Mac OS 10.4.5 might be the culprit since this problem seems to have occurred shortly after I upgraded???
    Thanks,
    -AstraPoint

    Hi,
    Assumptions :-
    uuencode command exits
    mailx command exits
    File name is "vas.txt".
    Mail id is "[email protected]"
    # START OF SCRIPT
    #!/bin/ksh
    vasFileName="$1"
    vasRecordsDirFile=/etl/dev/work/wellness/enrl_rej/records/${vasFileName}
    vasMetatdataDirFile=/etl/dev/work/wellness/enrl_rej/metadata/${vasFileName}
    vasHeaderDirFile=/etl/dev/work/wellness/enrl_rej/header/${vasFileName}
    vasHeaderRejDirFile=/etl/dev/work/wellness/enrl_rej/hdrrej/${vasFileName}
    vasFieldsDirFile=/etl/dev/work/wellness/enrl_rej/fields/${vasFileName}
    if [[ -e ${vasRecordsDirFile} ]]
    then
    uuencode ${vasRecordsDirFile} ${vasRecordsDirFile} | mailx -s "process complete and attached are the rejected records" [email protected]
    elif [[ -e ${vasMetatdataDirFile} ]]
    then
    uuencode ${vasMetatdataDirFile} ${vasMetatdataDirFile} | mailx -s "Metadata Mismatch no of fields in detail didn't match" [email protected]
    elif [[ -e ${vasHeaderDirFile} ]]
    then
    uuencode ${vasHeaderDirFile} ${vasHeaderDirFile} | mailx -s "Problem with header file - File Rejected" [email protected]
    elif [[ -e ${vasHeaderRejDirFile} ]]
    then
    uuencode ${vasHeaderRejDirFile} ${vasHeaderRejDirFile} | mailx -s "the Percentage of rejects more than 3 percent File rejected" [email protected]
    elif [[ -e ${vasFieldsDirFile} ]]
    then
    uuencode ${vasFieldsDirFile} ${vasFieldsDirFile} | mailx -s "The header and detail count didn't match File rejected" [email protected]
    else
    echo "File doesn't exist in any of the directories mentioned."
    fi
    # END
    Vijay Bheemineni.

  • Help with moving contact info using Apple Script in Address Book

    Hi folks,
    I wonder if someone can help? I imported a few hundred contacts via a Gmail created vCard into my Address Book. The problem is that instead of inserting the email addresses into one of the email fields for each record, it has inserted the email address into the Notes field as follows: "EmailAddress: [email protected]".
    I would like help to write an Apple Script that will search my contacts in Address Book, find those with "EmailAddress:" in the notes field, cut the email address that follows it, and pastes it into the Work Email field, carries out the operation for the whole address book and saves the changes.
    Can anyone help me write a script for this. I've not used Apple Script before so this will be my first attempt!
    Thanks in advance,
    ayworld

    This should work:
    tell application "Contacts"
      activate
              set thePeople to every person whose note contains "EmailAddress:"
              set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
              repeat with thePerson in thePeople
                   set nn to thePerson's note
                    make new email at end of emails of thePerson with properties {label:"Notes", value:text item 2 of nn}
              end repeat
      save
    end tell
    It will leave the entry in notes and make the label of the new email 'Notes"
    Normally when I post an AppleScript like this I tell the user to test it out before using it on the actual data but in this case I don;t know how you'd do that given there is only one Contacts and only one Contacts database.
    Just make sure you have a backup just in case. I tried it here on some dummy entries in my Contacts and it worked OK.
    Again this totaly relies on the data you presented. The Notes field has to be in the format
    EmailAddress:[email protected]
    for this to work.
    regards
    Message was edited by: Frank Caggiano - If you select all the text in the box, then right click and select Make new AppleScript the script will open in the AppleScript editor. Just make sure you get all the text it is easy to drop the first or last char when selecting.

  • Help with Apple Script Code

    Hi,
    I found this Apple script online and here's how it works:
    tell application "QuickTime Player"
    activate
    try
    if not (exists document 1) then display dialog "Please open a QuickTime movie." buttons {"Cancel"} default button 1 with icon 1
    set thefile to (choose file name)
    save document 1 in thefile
    close document 1
    end try
    end tell
    +I run the Apple script+
    *1. It prompts me to open a movie file in Quicktime*
    +I open a movie in Quicktime+
    *2. It prompts me for an name and directory to save the new file in*
    +I enter a name and directory+
    *3. It saves a new reference movie in said directory with said name*
    This is useful if I want to customize every file, but unfortunately, I just want to mass create reference movies for a whole bunch of files.
    What I am looking for is for an Apple script that is a drag and drop application, so I can drop say 100 movie files or so, and have the Apple script create reference movie files with the same name and in the same directory automatically with no prompts.
    Since I am unfamiliar with Apple script I was wondering if someone would be able to edit my existing script to do what I want.
    Thanks so much for your help!

    Use Automator. It's great for repetitious tasks (like the one you've described), and it's very user-friendly. Open Automator, create a new workflow that executes the action you want, and you can apply that action to the resources you wish to edit.
    Good resource here:
    http://bit.ly/

  • HELP : APPLE SCRIPT ISSUES!

    I am trying to make an apple script that will detect when an application (minecraft,cod or other online downloaded software/games) is open and then bring up a dialog that wont go away so that only I.T. can remove it. I also want it to send an email to a certain adress saying that so and so has been playing games
    It's a school project that im working on, we have to figure out a way (through applescript) to help students be more productive, everyone else has no experience with apple script but me. I managed to create this in a couple of minutes but there is a couple glitches and problems i cant solve.
    the problems include
    it doesn't work with non-appstore apps ie. apps downloaded for the internet
    i want it to be able to detect numerous programs
    it doesn't close the program and/or bring the window/dialog to the top.
    I have used safari as an example as to where a list of "illeagle apps" should be.
    here's the script:
    tell (get system info)
              set longName to long user name
              set shortName to short user name
    end tell
    if appIsRunning("Safari") then
              tell application "Mail"
                        set theNewMessage to make new outgoing message with properties {subject:"[" & longName & "] ,Gaming Alert", content:"[" & longName & "] has been gaming, he is to report to I.T. by the end of the day", visible:true}
                        tell theNewMessage
      make new to recipient at end of to recipients with properties {address:"[email protected]"}
      send
                        end tell
              end tell
    end if
    end
    repeat
              if appIsRunning("safari") then
                        display dialog "Gaming is not allowed, Your log of your computer programs running has been emailed to the I.T. department. Please visit the I.T. department immedietly to remove this message" buttons {"Report To I.T."} default button 1 cancel button 1 with title "Gaming Alert" with icon stop
              end if
    end repeat
    if appIsRunning("safari") then
              tell application finder
                        quit appIsRunning("safari")
              end tell
    end if
    on appIsRunning(appName)
              tell application "System Events" to (name of processes) contains appName
    end appIsRunning
    end
    Any help is greatly appriciated
    Thanks! 

    I really do not appreciate your negativity towards this assignment.
    firstly i am not trying to "cheat" the system by asking for help, our teacher encourges us to go online , reserch and go onto forums such as these.
    Secoundly , I dont need you to criticize my idea's by telling me that i am a "taddle tale" or whatever
    Thirdly , it's called updating over wifi. Thats how I intend on updating the blacklist to new games
    Finally it will encourage student productivity, as without games there will be no distractions. Internet games and such are blocked and I plan to keep my identity, as the creator of the script , a secret
    And also, here's a bit of criticism maybe you would be a better educationalist yourself if you actually encouraged a project.
    Ps. Are you familiar with google science fair... if not LOOK IT UP!
    im going i have talked viney kumar and are most likley teaming up to put this project in action, we go to the same school. He thinks it is a good idea and if YOU ever had any idea's at all that aren't criticism maybe you would have at least one atom that is up to his standard of innovation.bye the way, i am only 14.What were you trying to do when YOU were 14...
    Signed
    Steves Assistant

  • Looking a Apple Script please Help !

    I am looking for a Apple script which I start the Mac App Store and dirket jump to the updates. Is that possible?  If so  can i combine that  with the Automator on Mac ?

    Can you post more information?
    What happens when you type "python script.py"?  Do you get some sort of error message?
    If you type only the name of the script then you will have to make sure you have changed directory to where the script is located first. For example if your script is saved to your desktop, when you start Terminal you will first need to do "cd ~/Desktop" to change directory.
    Or alternatively you could type the path to the script:   python ~/Desktop/script.py
    Steve

  • I need help writing an apple script

    earlier I made an application with automater saying that when it opens it would add something to my todo list, for example, the subject being english and priority being very high. Then I made an apple script telling it to open the application I made. Then I made a mail rule telling it that if i text my computer and the text includes english and very important (english is subject and very important is the priority) it would open the apple script that tells the application i made to open and put english in my todo list. Can someone tell me how I can make a script in which it puts whatever I text my computer in my todo list, so if i text my computer anything random it would put it in my todo list

    Well after a bit of head scratching I have done it! And it was simpler than I expected although I'm sure the script can be improved, it does what I want it to do. Any suggestions on improvements would be welcome.
    Andy E
    The script...
    set artistName to text returned of (display dialog “Enter artists name:” default answer “”)
    set artistSortName to text returned of (display dialog “Enter artists sort name:” default answer “”)
    if artistName is “” then
    set tempVer to display dialog “No artist name specified!” buttons {“OK”}
    return
    end if
    if artistSortName is “” then
    set tempVer to display dialog “No artist sort name specified!” buttons {“OK”}
    return
    end if
    tell application “iTunes”
    activate
    set theLibrary to library playlist “Library”
    set searchList to search theLibrary for artistName
    repeat with thisTrack in searchList
    set thisArtist to artist of thisTrack
    if thisArtist is equal to artistName then
    set sort artist of thisTrack to artistSortName
    end if
    end repeat
    end tell
    15" MacBook Pro 2.16GHz, 2GB Ram   Mac OS X (10.4.10)   It's my first Mac and I love it!

  • Need help writing and Apple Script

    I've never written an apple script before so I need the entire tutorial for dummies. Basically, I am annoyed with the fact that Microsoft Word 08 keeps opening a new document at 100% zoom when I want it to open at "page width." How do I write a script for that?

    You don't need an Applescript. Open the New Document template, resize as you like then save the template.
    To learn Applescript start here. You will also find support at the Applescript site for developers. Your local book store or Amazon.com have dozens of books on Applescript programming.
    Here's the main site for obtaining Applescripts.

  • How to disable the option of "Overprint [Black] Swatch at 100%" in Indesign by Apple Scripting

    Hi Friends,
    I am new to Indesign Scripting by Apple Script. As a beginner, I am trying to do some basic scripting in Indesign by Apple Script.
    My aim is to disable the option of "Overprint [Black] Swatch at 100%" in Indesign. This option is available when we go to Indesign ---> Preferences----> Appearance of Black.
    Also, if a user opens a file, in which the swatch is already enabled, then it should prompt him for disabling.
    I can make a display dialog in AppleScript. But, I am bit unsure as how can I go ahead and disable this option. I tried this below script:
    tell application "Adobe InDesign CS4"
          tell every layout window to set overprint preview to false
    end tell
    However, it is changing the view option to overprint preview.
    Appreciate your help and suggestions!
    Thanks,
    Abhishek

    tell application "Adobe InDesign CS5"
              tell the active document
                        set overprint black of document preferences to false
              end tell
    end tell

Maybe you are looking for