So I have this AppleScript for making aliases of all the contents of one folder to another folder.
I works perfectly unless there is only one item in the source folder.
tell application "Finder"
set SourceFolder to (choose folder with prompt "Please choose Source folder:") as string
set DestinationFolder to (choose folder with prompt "Choose Destination folder for aliases:") as string
set theFolders to every item of entire contents of folder SourceFolder
repeat with thisFolder in theFolders
set thisName to name of thisFolder
make new alias file at folder DestinationFolder to thisFolder without invisibles
end repeat
end tell
Any idea why it's not getting anything when there's one item only? When there's at least 2 items in the source folder it creates aliases for both in the destination.
On a side note, any way to get it to remember the source and destination folders between times you run it?
Try:
property SourceFolder : missing value
property DestinationFolder : missing value
if SourceFolder = missing value then
set SourceFolder to (choose folder with prompt "Please choose Source folder:")
set DestinationFolder to (choose folder with prompt "Choose Destination folder for aliases:")
else
tell application "Finder"
set theFolders to every item of entire contents of SourceFolder as list
repeat with thisFolder in theFolders
make new alias file at DestinationFolder to thisFolder
end repeat
end tell
end if
Related
I need to modify my current code to allow for the selection of a a folder. My current code is as follows and works to select a folder without issue:
tell application "Finder"
set sourceFolder to folder POSIX file "/Users/Username/Desktop/Upload/Temp/HighRes/"
set theFiles to files of sourceFolder
set inputPath to "/Users/Username/Desktop/Upload/Temp/"
end tell
I have tried the following, but cannot determine the correct syntax to get to where I was in my original code
tell application "Finder"
set inputPath to folder POSIX file (choose folder with prompt "Please choose folder to be processed")
set sourceFolder to folder POSIX file (inputPath & "/HighRes")
set theFiles to files of sourceFolder
end tell
The above processes but errors out and says that finder got an error and cannot make alias "xyz" into type integer.
Please forget the POSIX dance. The Finder likes its native and alias specifiers.
tell application "Finder"
-- inputPath is an alias specifier
set inputPath to (choose folder with prompt "Please choose folder to be processed")
-- sourceFolder is built as a Finder item specifier
set sourceFolder to folder "HighRes" of inputPath
set theFiles to files of sourceFolder
end tell
Even your first snippet can be written in a simpler way
tell application "Finder"
set sourceFolder to folder "Upload:Temp:HighRes" of desktop
set theFiles to files of sourceFolder
set inputPath to folder "Upload:Temp" of desktop
end tell
I have a folder that is three levels deep, each level contains a good amount of files. I am able to get two levels deep with the script below, however the third level is posing a bit of a challenge. Would someone mind offering some guidance as to how I am supposed to get one level deeper? Use python or another language wouldn't be acceptable, as I am trying to see how this works with AppleScript.
set sourceFolder to (choose folder)
tell application "Finder"
my changeFileNameCase(sourceFolder, "upper")
repeat with subFolder in (get every folder of folder sourceFolder)
my changeFileNameCase(subFolder as alias, "upper")
#This Is No Good
repeat with theFolder in (get every folder of folder subFolder)
my changeFileNameCase(theFolder, "upper")
end repeat
end repeat
end tell
on changeFileNameCase(targetFolder, caseToSwitchTo)
tell application "Finder"
set fileList to every file of folder targetFolder
repeat with theFile in fileList
set oldName to name of theFile
set newName to my changeCaseOfText(oldName, caseToSwitchTo)
set the name of theFile to newName
end repeat
end tell
end changeFileNameCase
To make the handler recursive you have to get all items of the folder and check the class of each item.
If the class is folder call the handler passing the folder
If the class is file rename it
set sourceFolder to (choose folder)
changeFileNameCase(sourceFolder, "upper")
on changeFileNameCase(targetFolder, caseToSwitchTo)
tell application "Finder"
set theList to every item of targetFolder
repeat with i from 1 to count theList
set theItem to item i of theList
if class of theItem is folder then
my changeFileNameCase(theItem, caseToSwitchTo)
else
set oldName to name of theItem
set newName to my changeCaseOfText(oldName, caseToSwitchTo)
set name of theItem to newName
end if
end repeat
end tell
end changeFileNameCase
I have a drive that has multiple "Approved" folders with files in them.
The Approved folders are in various locations on the drive.
I need to move the contents of the Approved folders to another directory via applescript.
This is what I have come up with so far but does not seem to be doing the trick, it runs but no files are moved...
Any tips would be great
Thanks
set sourceFolder to "THIS:" as alias
set destinationFolder to "THAT:" as alias
tell application "Finder"
repeat with aFolder in (get folders of sourceFolder)
set folderName to name of aFolder
set filesToMove to (files of sourceFolder whose name = "Approved")
move filesToMove to destinationFolder
end repeat
end tell
According to your description, you are looking for folders named Approved, but your script is searching for files named Approved. Try this:
set sourceFolder to choose folder
set destinationFolder to choose folder
tell application "Finder"
repeat with aFolder in (get folders of sourceFolder)
if aFolder's name is "Approved" then
set filesToMove to (files of aFolder)
move filesToMove to destinationFolder
end if
end repeat
end tell
I have the following applescript that takes files and puts them in their corresponding folders.
set sourceFolder to choose folder
tell application "Finder"
set theFiles to files of sourceFolder
repeat with aFile in theFiles
set fileName to name of aFile
if fileName contains "#" then
set poundOffset to offset of "#" in fileName
set folderName to text 1 thru (poundOffset - 2) of fileName
set newFolder to (sourceFolder as text) & folderName & ":"
if not (exists folder newFolder) then
make new folder at sourceFolder with properties {name:folderName}
end if
move aFile to folder newFolder
end if
end repeat
end tell
It works great for me except in the case of a file conflict. If there's a file with the same name in the folder that it's putting it in the script gets an error and crashes. So my question is this....How do I fix that? I'm willing for it to just overwrite the file but is there a way to bring up a prompt to skip the file or just skip it all together and move on to the next one?
I'm a little fuzzy on what I can do here. Thanks in advance for the help.
Ringslinger.
Try:
move aFile to folder newFolder replacing true
I'm trying to create an applescript that will essentially pull a movie file from a folder when that folder is added to a directory. For instance, when I add a folder containing a movie and other files to my "Movies" directory, I want to be left with the movie file itself, deleting the other unneccesary files.
I've been able to make this work with a manual script but I'd like it to run automatically on add. I think part of the issue is handling the folder coming in. I'm not sure how "these_items" is processed. I've tried handling it as if it were a file and if it was a list of files in the folder.
Here's my attempt so far. I have lines commented out from different trials and I'm using ~/Desktop as my destination folder right now for simplicity.
on adding folder items to this_folder after receiving these_items
tell application "Finder"
--if kind of these_items is "Folder" then
--set this_folder to (path to these_items)
set this_list to every file of these_items
--repeat with i in this_list
--set this_list2 to every file of i
repeat with i from 1 to number of items in this_list
if (name of i) ends with ".mp4" then
move i to (path to desktop folder)
move i to trash
end if
end repeat
--end repeat
--end if
end tell
end adding folder items to
Attach this folder action to your "Movies" directory:
on adding folder items to theFolder after receiving theItems
set destFolder to path to desktop
repeat with anItem in theItems
tell application "Finder"
if kind of anItem is "Folder" then
move (files of (entire contents of anItem) whose name extension = "mp4") to destFolder
delete anItem
else if name extension of anItem = "mp4" then
move anItem to destFolder
else
delete anItem
end if
end tell
end repeat
end adding folder items to