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

Similar Messages

  • Apple script to batch rename files by deleting tags on front and back of the file name

    Hi, I'm trying to rename a couple thousand files from their current format:  "01074_Something Of A Dreamer_Mary-Chapin Carpenter.lrc"
                                                                                                                           "01075_Where Did We Go Right_Lacy J. Dalton.lrc"
                                                                                                                           "01076_Everybody's Reaching Out_Crystal Gayle.lrc"
                                                                                                         To simply:  "Something Of A Dreamer.lrc"
                                                                                                                           "Where Did We Go Right.lrc"
                                                                                                                           "Everybody's Reaching Out.lrc"
    I just want to delete the number tag on the front and the artist name at the end for all of the files.  I imagine a Script to do this wouldn't be too hard to write, something along the lines of read file name after the first '_' character it reads until it reads a second '_' character and rename the file to the string it reads between those two underscores with .lrc at the end.
    Unfortunately I know nothing about Apple Script other than it seems like the thing I would need to automate this process based on my limited google searches.  If someone could help me out with some advice on how to go about making this script or obviously if you simply have and/or can quickly write a script to do this it would be greatly appreciated!

    Here:
    tell application "Finder"
    repeat with this_file in (get files of window 1)
    set the_name to name of this_file
    set temp_name to items ((offset of "_" in the_name) + 1) thru -1 of the_name as string
    set temp_name to (items 1 thru ((offset of "_" in temp_name) - 1) of temp_name as string) & items -4 thru -1 of the_name as string
    set name of this_file to temp_name
    end repeat
    end tell
    (123647)

  • 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/

  • 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!

  • 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?

  • Apple Script to rename images using CSV file

    Hello, I have build a website using a Woocommerce for Wordpress. The site is going to have over 1200 images and they need to be renamed appropriately for each product. I've never used Apple Script before but after hours and hours of searching I have noticed people with similar issues have managed to solve the problem using AppleScript.
    I have attached a screenshot of the CSV file first 20 files - also the images are all saved in a folder with the names _DSC7916 copy 2.jpg etc etc.
    Hopefully my issue makes sense,

    In applescript it goes something like this:
              this all assuming the CSV file is a plain text file with a comma delimiting
              the old and new filenames on a given line. If you have another structure
              you need to give specifics so this can be modified
    set theCSVData to paragraphs of (read "/path/to/theCSVFile.csv")
    set {oldTID, my text item delimiters} to {my text item delimiters, ","}
    repeat with thisLine in theCSVData
              set {oldFileName, newFileName} to text items of thisLine
              tell application "System Events"
                        set name of file oldFileName of folder "path/to/folder of images" to newFileName
              end tell
    end repeat
    set my text item delimiters to oldTID
    Note that I've made a lot of assumptions about your csv file, any or all of which may be wrong. please clarify as needed.

  • 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

  • Apple Script - Simple Navigation thru Preferences

    Howdy,
    I'm trying to us Apple Script to simply change my Network Location. I thought it would be easy, I must be missing something. Here is the code I've written so far that works...
    tell application "System Preferences"
    activate
    set current pane to pane "Network"
    end tell
    Now, I want to change the Location field (I believe it's called an anchor) to my secondary (Home, for example). So, I added a line like such...
    tell application "System Preferences"
    activate
    set current pane to pane "Network"
    set anchor to "Location"
    end tell
    This 4th line doesn't work, but you get the idea. I have written many variations of this 4th line (i.e. 'set "Location" to "Home"'), nothing seems to work. And there doesn't seem to be much documentation on anchors (other than what's in the Dictionary).
    Recording doesn't save it, so that's out of the question.
    Does anyone have any ideas?? Thanks.
    Bryan
    iMac Intel   Mac OS X (10.4.7)  
    iMac Intel   Mac OS X (10.4.7)  

    Surround the line...
    click button "Apply" of sheet 1
    ... with 'try ... end try', as shown below ...
    try
    click button "Apply" of sheet 1 -- Select the'Apply' button of drop down sheet.
    end try
    Full code, with comments:
    property tMenu : "Home" -- The menu item to select.
    tell application "System Preferences" -- Launch application
    activate
    set current pane to pane "com.apple.preference.network" -- Select 'Network' utility.
    end tell
    tell application "System Events" to tell process "System Preferences"
    tell window 1
    click pop up button 1 -- Select the 'Localtion' popup button.
    click menu item tMenu of menu 1 of pop up button 1 -- Select the 'tMenu' menu item.
    click button "Apply Now" -- Select the 'Apply Now' button.
    click button 1 -- Select the Close button.
    try
    click button "Apply" of sheet 1 -- Select the'Apply' button of drop down sheet.
    end try
    end tell
    end tell

  • 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 do I install and apple script in mail

    I am using  dreamhost as my ISP. I am  getting killed with spam and the have a  script. I found out how to add  the script via the rules function, but,  how do you store the script in  the location you need to retreive it  from. there I can't find info. Can  someone give me steps please? Do you  make a text file, etc?

    Select Mail Help from Mail's Help menu. Search for "install apple script."
    Use scripts as rule actions
    You can attach a script to a Mail rule. For example, you could have an incoming message trigger a script that copies information from the message and pastes it into a database that works with AppleScript.
    Open Mail
    Choose Mail > Preferences, then click Rules.
    Add a rule or select an existing rule to edit.
    Choose Run AppleScript from the “Perform the following actions” pop-up menu.
    Choose a script from the pop-up menu of scripts that are located in ~/Library/Application Scripts/com.apple.mail. Or choose “Open in Finder” to open the folder so you can copy a script into it.If you later move or rename the script, your rule will not work.
    Click OK to save the rule.
    If you used scripts in Mail rules in OS X Lion or earlier, then the first time you open Mail in OS X Mountain Lion or later, your scripts are moved to ~/Library/Application Scripts/com.apple.mail, and your rules are updated with the new location. To show your home Library folder, hold down the Option key, then in Finder choose Go > Library.
    If you use iCloud Documents & Data, your rules are available on your other Mac computers (with OS X 10.8 or later) that have iCloud Documents & Data turned on. Scripts attached to rules aren’t available.

Maybe you are looking for

  • Creating less scenes

    I believe I need to merge clips so that when I import to iDVD I can create a movie with less scenes. The problem is each clip, approx. 55 - 60 will import as 1 scene in iDVD. The problem 4 clips might be the same thing. So for example My daughter is

  • ITunes keeps asking for a disk while I am trying to uninstall

    I am trying to uninstall iTunes so that I can reinstall it.  However, it keeps asking for a disk.  Also I have tried to use Windows Cleanup Utility 7.2, but get an error when I attempt to run it.  I think I may have started uninstalling the component

  • Another instance of a corrupt Micro SD card

    This problem is somewhat similar to the one described here, but with a 16 GB card rather than an unsupported 64 GB card: Micro SD Card Became Corrupt history: I am using a fast 16 GB card (SanDisk microSDHC 16GB Extreme Pro) which I used with my Andr

  • Using XA Library from with OCI application

    Are there any sample/demo programs that illustrate how to use the XA interface from within an OCI application? In particular, I'm wondering about the association between the OCI session and the xa_open() session -- how can one use OCI calls after est

  • [URGENT]: legacy asset master upload including values

    Hi, I am having trouble uploading asset master including values. Has anyone done this before. PLease help me out. I have tried to use lsmw standard batch input method, but after assigning everything when i do the last but one step Create Batch Input