Moving a file using AppleScript not working after changing the file name

applescript rename file
automator move files to new folder
applescript move file
automator move files from subfolders
automator copy files from one folder to another
automator folder actions examples
automator folder action not running
folder action scripts

I'm using AppleScript to rename a file and move it to a folder. This is executed using a voice command. It doesn't move the file to the folder, it presses Enter, renames the file to "myFile", presses Enter again.

However, if I execute this a second time, or if the file is named "myFile", It will work. I think the code that moves the file doesn't know, or is not updated on the file name. I don't know how to fix this. AppleScript is not my thing.

tell application "System Events"
    key code 36
    keystroke "myFile"
    key code 36
end tell

tell application "Finder"
    move POSIX file "/Users/joe/Desktop/myFile.csv" to POSIX file "/Users/joe/Desktop/TestFolder" with replacing
end tell

With the file selected, try this:

tell application "Finder"

    set itemlist to the selection
    set theFile to (item 1 of itemlist) as alias
    set name of theFile to "myFile.csv"

    move POSIX file "/Users/joe/Desktop/myFile.csv" to POSIX file "/Users/joe/Desktop/TestFolder" with replacing

end tell

MacScripter / move a selected file and change its name, Using applescript I want to move a file that is selected in the Finder to another folder and also change the name of the file being moved. The problem you've found is that the Finder's references to folders and files are name references. When you This will keep track of the file after it's renamed or moved:  If you want to do a copy, instead of moving the files, change the line. move source_file to (target_folder) to. copy source_file to folder (target_folder as alias) Sources used. MacUser.de discussion about “Move Files using AppleScript” (DE) MacUser.de discussion about “Copy Files using AppleScript” (DE)


If the file you want to move is currently selected in Finder and you would like to be able to set the new name… this solution may work for you

property moveToFolder : (path to desktop as text) & "TestFolder"

set newName to text returned of (display dialog "Name Your File" default answer ¬
    "myFile.csv" buttons {"Cancel", "OK"} ¬
    default button 2 cancel button 1 with title "Name Your File")

tell application "Finder"
    set originalFile to item 1 of (get selection) as alias
    set theFile to (move originalFile to alias moveToFolder) as alias
    if (exists of alias (moveToFolder & ":" & newName)) then ¬
        delete alias (moveToFolder & ":" & newName)
    set name of theFile to newName
end tell

Applescript problems with renaming a file and getting the alias to , I think that got broken somewhere, as an alias is supposed to be a reference to a file item that remains valid even if it gets renamed or moved. class (via some AppleScriptObjC) to keep track of the file references, since that reference from path tell application "System Events" to set the name of disk item  We will use a standard AppleScript called “Replace Text in Item Names”. Basically it will take a group of files or folders and perform a find and replace on their names. While there may be a million different reasons to use this script, a common one, and one that I deal with a lot, is to rename a series of screen grabs.


Don't GUI script actions that can be natively commanded through AppleScript.

To rename and move a file using System Events:

tell application id "sevs"
    set base_folder to folder "~/Desktop/"
    set f_old to "myOldFile.csv" -- file to move (original name)
    set f_new to "myFile.csv"    -- new file name
    set dir to "TestFolder"      -- destination folder

    tell the base_folder 
        set the name of the file named f_old to f_new
        move the file named f_new to the folder named dir
    end tell
end tell

To rename and move a file using Finder:

tell application id "MACS" --OR: "com.apple.Finder"
    set base_folder to folder (POSIX file "/Users/joe/Desktop/")
    set f_old to "myOldFile.csv" -- file to move (original name)
    set f_new to "myFile.csv"    -- new file name
    set dir to "TestFolder"      -- destination folder

    tell the base_folder 
        set the name of the file named f_old to f_new
        move the file named f_new to the folder named dir with replacing
    end tell
end tell

Essentially, having broken the paths down as I have, both scripts are the same except for the value assigned to the variable base_folder, for which Finder needs to be made explicitly aware it's dealing with a filepath in posix notation. Alternatively, in the specific case where the base folder is the desktop folder, both Finder and System Events should be able to understand this:

set base_folder to the path to the desktop folder

How to move files to folders based on nam…, Will those student documents have filename extensions in addition to the name student of destination -- error if folder does not exist set name of aFile to (project This is very helpful, but I am rather new to applescript and so I am a bit After placing the script in your user's ~/Library/Scripts/Folder Action  Instead of the using the ThisWorkbook.Worksheets collection we use the CODENAME of the worksheet. Just what is the CODENAME you ask. If you take a look at the Project Explorer in your VBA screen worksheets have 2 names. One of them in parentheses. The name in parentheses is the sheet name we are used to. The name to left of that is the CODENAME.


Beginning AppleScript, When you identify a file by name in AppleScript, you must also use its extension. So the following would be a valid path to a script stored on my system: Macintosh however, is not a valid path: Macintosh HD:Users:steve:MySrc:scripts:ch6:​population the way programmers work with devices, directories, and ordinary files. Original title: Cannot send/receive after moving .pst file - solved. Outlook 2010 running on Windows 7 Professional. A hard drive failure forced me to move the .pst file to a different hdd and thereafter I could not send nor receive. I figured out the problem was that the email accounts lost track of the delivering folder.


Learn AppleScript: The Comprehensive Guide to Scripting and , The Comprehensive Guide to Scripting and Automation on Mac OS X Hamish Pages application, 744 file names batch-changing with Satimage scripting addition, 417–418 File not found error, 491 File not open with write permission error, 606–607 mounting volumes, 618–621 moving files and folders, 605 opening  To Move the File, Please refer to Move File Using File System Task article present in the SSIS page. We have File System Task Folder inside the MSBI Folder. Our task is to move the GEOGRAPHY.txt file inside the File System Task Folder to Copied Folder inside F Drive and rename it.


Mac OS X Hints: Jaguar Edition, In that system, if you added punctuation in front of a folder or file name, the item the file's name (use the arrow keys to move around within the name), press Enter, The trouble with that method is that each time you press Enter after editing a name, The solution, of course, is to put the list view into a sorting order that isn't​  How to use “move…” verb to move sheets in Numbers? applescript,applescript-numbers. The move in the Numbers dictionary is part of the Standard Suite, which typically works with files. I have tried using it to move text items and tables from one sheet to another, but it always fails.