I need to MOVE (not copy) every file (including subfolders) in "Downloads" to an external drive called "Drive" in the location "Volumes/Drive/Apple/MacBackup/Downloads". I have tried countless times and it is just not working... Here is my code right now:
tell application "Finder" to move entire contents of folder "Users:myUsername:Downloads" to folder "Drive:Apple:MacBackup:Downloads"
I am getting the error:
Finder got an error: Can’t get folder "Users:myUsername:Downloads".
HFS paths have to begin with the name of the disk, like
"Macintosh HD:Users:myUsername:Downloads"
You have probably taken it from a POSIX path, were the first slash represents the startup volume.
To be sure just run
choose folder
and copy the path from the result.
The error is because that is not a correctly formed path. You should use the special folder designation (path to downloads folder).
tell application "Finder" to move entire contents of (path to downloads folder) to folder "Drive:Apple:MacBackup:Downloads"
Also, I would strongly encourage you to copy the files, then delete the old files. Moving files is asking for trouble if something happens mid-process, and it's lost in transit. (think star trek transporter problem)
Related
I have close to zero AppleScript experience and very little Automator experience too, so please bear this in mind. What I'm asking might be REALLY obvious to you, but I'm somewhat stuck.
I want to create a workflow (saved as an App) where I can drag a folder and it does a few things:
Copies the source folder
Sets some background colors on the copied folders
Deletes any folders that are empty
I found a script that does the deletion, but it was set to reference a specific folder. I want it to reference the folder that I have just copied:
tell application "Finder"
set the_items to every folder of entire contents of folder "$CopiedFolderHere"
...
Image of the Workflow is here
I would really appreciate it if someone can tell me what I need to tweak in the script to allow it to make the deletions on the newly-copied folder.
Thanks :)
I have recently started a little project of mine using languages such as Python or AppleScript to manipulate files and other things on a Mac. I am making multiple different programs that do these things.
Recently I began to write a program that changes the desktop background to a file on the USB stick that the program is located on. It is intended to work across different computers, so I have to keep it on the USB stick.
The issue is that when I run the program from my computer, the AppleScript seems to not be able to find the files on the USB. I am also not sure whether or not I will need to change the code when I move the program onto the USB.
The program works fine when I use files on the computer itself, but it seems to come up with an error every time it tries to retrieve an image from the USB.
Here is the appropriated code.
set Username to system attribute "USER"
set Photo to (random number from 1 to 5) as text
tell application "Finder"
make new folder at desktop with properties {name:"DesktopFolder"}
move entire contents of folder "USB/Photos/" to folder "Users/" & Username & "/Desktop/DesktopFolder/"
set desktop picture to POSIX file "/Users/" & Username & "/Desktop/DesktopFolder/Image" & Photo & ".png"
end tell
Of this, the line move entire contents of folder "USB/Photos/" to folder "Users/" & Username & "/Desktop/DesktopFolder/" is the one producing the following error Finder got an error: Can’t get folder "USB/Photos/".
What I would like to happen is that the images from the USB are copied into the new folder on the desktop, and then a random photo from this folder is chosen as the new desktop background.
Any help would be appreciated. Thanks!
The main issue is that Finder doesn't understand posix paths (i.e. slash notation); it operates using HFS paths, which uses colons in place of slashes, and substitutes in the disk name at the beginning of the file path.
So, the equivalent HFS path that points to the same location as the posix path
/Users/{{user}}/Desktop/DesktopFolder/Image4.png
is written as
Macintosh HD:{{user}}:Desktop:DesktopFolder:Image4.png
Therefore, to point to a folder on your USB drive named "USB", you would write:
USB:Photos:
Here's a modified and corrected/improved edit of your script:
set n to (random number from 1 to 5) as text
tell application "Finder"
set F to make new folder at desktop with properties {name:"DesktopFolder"}
move every item of folder "USB:Photos:" to F
set desktop picture to the file ("Image" & n & ".png") in F
end tell
I've done away with a lot of your path references that were expressed explicitly as broken string fragments, and instead set a variable to store a reference to the location of the folder you make on your desktop. That way, you can use the variable reference to target that folder for moving and selecting files.
I'm trying to duplicate my desktop file on apple script using script editor but I can't figure out how to do it. Can someone please help me?
The following command will duplicate your Desktop folder in Finder as Desktop copy and will be in your Home folder:
tell application "Finder" to duplicate desktop
The following commands will duplicate the target object directly on the Desktop, i.e., objects within the Desktop folder in your Home folder in Finder .
The following command will duplicate every file on your Desktop:
tell application "Finder" to duplicate every file of desktop
The following command will duplicate every folder on your Desktop:
tell application "Finder" to duplicate every folder of (path to desktop)
The following command will duplicate every file and folder on your Desktop:
tell application "Finder" to duplicate every item of (path to desktop)
NOTES:
This is to address the comment made by has:
As to: "1. You don’t need path to desktop as Finder’s application object already has a desktop property containing a reference to the user’s Desktop."
This is not categorically a true statement and depends on how it's being used. It's true with the Desktop folder itself and files within the Desktop folder, however it is absolutely false with duplicate every folder of and duplicate every item of, and without using (path to desktop) in these instances it errors out with the following error statement:
"Finder got an error: The folder “” can’t be moved into itself." number -122
As to: "2. Never do duplicate every item of desktop – if the Finder’s preferences are set to display mounted volumes on the Desktop then those will be included too, and you definitely don’t want to duplicate those!"
That statement is categorically false!
He/she (has) obviously doesn't know what he/she is talking about because mounted volumes are not located within the Desktop folder in your Home folder. By default, they are mounted at /Volumes and while they can appear on the Desktop, they are not directly connected to the Desktop folder in your Home folder.
In this reference the Desktop and Desktop folder in your Home folder are not the same thing!
I'm trying to move a user-selected folder to another folder, but I don't get it: whenever I look it up, it looks too complicated, even though I know it's not supposed to be.
Here's the code I have so far - please help:
choose folder with prompt "Select folder:"
on open of finderObject
tell application "Finder" to move (finderObject) to folder "Library:Application Support"
end open
end
First off, you have to assign the chosen folder to a variable.
Also, many special folders in the OSX file structure have special names to get their paths, including the library and the application support folders. So, your script can simply be:
set finderObject to choose folder with prompt "Select folder:"
tell app "Finder" to move finderObject to folder (path to Application Support folder from local domain as string)
However, that is the root level Library folder. I suspect you will want to use the Application Support folder in the ~/ user domain. For that, change the "from local domain" to "from user domain".
I am working on a script that will move the entire contents of a folder, including all subfolders and the files within, to another folder when I mount my bak drive.
Just for testing I wrote a simple script to check how I can do this (I don't really know AppleScript, so it's learn as I go), I used the following cmd in my applescript:
move every file of entire contents of folder "Lion:Users:dbooster:desktop:outbox" to "Lion:Users:booster:desktop:file"
So my test, as you can see is moving everything within a folder on my desktop called "outbox" into a folder called "file" on my desktop.
At first I thought it worked perfectly, but then I tried to put another folder within "outbox". What I discovered is this script moves all the files within that subfolder in "outbox", but it doesn't move the subfolder itself.
That is to say, if I test with outbox/stuff/file1.txt and run the script, the result is file/file1.txt, NOT file/stuff/file1.txt which is what I would expect.
Uhm... This seems like it should be easier than I am finding it. But I've been searching google for the past hour and can't come up with anything (maybe I'm searching for the wrong thing?) Any help would be appreciated -- thanks in advance.
Try:
tell application "Finder" to move entire contents of folder "Lion:Users:dbooster:desktop:outbox" to folder "Lion:Users:booster:desktop:file"