I am trying to find a way to do the following export
Current structure
Honeymoon
County
City
Album
I want to export the structure to say my pictures folder as
Honeymoon > County > City > Album > photo names
But I only want to choose the photos which have been edited (normally favourited)
I have found an AppleScript which will allow me to choose an album and export its contents
set dest to "/Users/adammann/Pictures/HoneymoonExports" as POSIX file as text -- the destination folder (use a valid path)
tell application "Photos"
activate
set l to name of albums
set albNames to choose from list l with prompt "Select some albums" with multiple selections allowed
if albNames is not false then -- not cancelled
repeat with tName in albNames
set tFolder to dest & tName
my makeFolder(tFolder) -- create a folder named (the name of this album) in dest
export (get media items of album tName) to (tFolder as alias) without using originals
end repeat
end if
end tell
on makeFolder(tPath)
do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder
But I am unable to get it to only export the "Favorite" ones it just exports all.
If anyone could help or point me in the right direction I would be greatful
Thanks in advance
Just use a filter:
export (get media items of album tName whose favorite is true) to (tFolder as alias) without using originals
Related
I am not a programmer by trade, but an art director on a rather large project where I do many repetitive tasks on a daily basis. One constant is moving files to team member's folders. I want to be able to select some files and have a menu appear for me to choose who will receive the files.
I made some progress but am stuck. The script cannot find the directory I intend the files to go. I fear it has something to do with POSIX paths - or me not defining it as a folder rather than a file? The error reads:
error "File /Volumes/Workbench/Test/CookieMonster wasn’t found." number -43 from "/Volumes/Workbench/Test/CookieMonster"
...even thou there is a folder where it says there isn't. I suspect my syntax is incorrect somehow.
set currentFolder to path to (folder of the front window) as alias
on error -- no open windows
set the currentFolder to path to desktop folder as alias
end try
set artistList to {"CookieMonster", "BigBird", "Bert", "Ernie", "Grouch"}
set assignTo to {choose from list artistList with title "Assign to..." with prompt "Please choose" default items "Bert"}
set assignedArtist to result
set artDeptDir to "/Volumes/Workbench/Test/"
set filePath to {artDeptDir & assignedArtist}
set destinationFolder to filePath as alias
set selected_items to selection
repeat with x in selected_items
move x to folder of filePath
end repeat
If anyone who has insight into my problem, I would love to hear from them. Thank you for taking the time to read this.
The main issue is that the Finder doesn't accept POSIX paths. You have to use HFS paths (colon separated and starting with a disk name).
This version fixes another issue and redundant code was removed
tell application "Finder"
try
set currentFolder to (target of the front window) as alias
on error -- no open windows
set currentFolder to path to desktop
end try
set artistList to {"CookieMonster", "BigBird", "Bert", "Ernie", "Grouch"}
-- no braces {} !
set assignTo to (choose from list artistList with title "Assign to..." with prompt "Please choose" default items "Bert")
if assignTo is false then return
set assignedArtist to item 1 of assignTo
-- no braces {} !
set destinationFolder to "Workbench:Test:" & assignedArtist
move selection to folder destinationFolder
end tell
In my example .CSV file, I have a column A with the following values: 2,2,5,5,5. In column B are hyperlinks to corresponding files that require downloading: http://example.com/2A.pdf, http://example.com/2B.pdf, http://example.com/5A.pdf, http://example.com/5B.pdf, http://example.com/5BC.pdf. Having difficulty creating an applescript that creates the DL folder (based on the non-unique column A value) and applies the DLs of any corresponding row to the appropriate folder. Any help would be greatly appreciated! TIA.
From your description, I am assuming the CSV file looks something like this:
2, http://example.com/2A.pdf
2, http://example.com/2B.pdf
5, http://example.com/5A.pdf
5, http://example.com/5B.pdf
5, http://example.com/5BC.pdf
and that the file 2A.pdf should end up in a directory called 2.
Assuming I have interpreted this correctly, here is the AppleScript that will achieve this (replace /Path/To/Save/Folder/ with the full path to the folder where these new files and folders will be downloaded, and /Path/To/File.csv to the full path of the CSV file):
-- Note: The ending / is essential in BaseDir
set BaseDir to POSIX file "/Path/To/Save/Folder/"
set rows to every paragraph of (read "/Path/To/File.csv")
set AppleScript's text item delimiters to {"/"}
set [TopDir, BaseFolder] to [text items 1 thru -3, text item -2] of ¬
POSIX path of BaseDir
-- Create initial base folder if it doesn't exist
tell application "Finder" to if not (exists BaseDir) then ¬
make new folder in (TopDir as text as POSIX file) ¬
with properties {name:BaseFolder}
-- This will prevent EOF-related errors
-- Thanks to #user3439894 for highlighting the need for this
set rows to reverse of rows
if the number of words of the first item in rows is 0 ¬
then set rows to the rest of rows
repeat with row in rows
set [N, |url|] to [first word, text items -2 thru -1] of row
-- Create folder into which file will be downloaded
tell application "Finder" to if not (exists [BaseDir, N] as text) then ¬
make new folder in BaseDir with properties {name:N}
-- This is the shell command that downloads the file
-- e.g. "cd '/Users/CK/Desktop/example.com/5'; curl example.com/5BC.pdf \
-- remote-name --silent --show-error"
set command to ("cd " & ¬
quoted form of POSIX path of ([BaseDir, N] as text) & ¬
"; curl " & |url| as text) & ¬
" --remote-name --silent --show-error"
-- Run the shell command
do shell script command
end repeat
-- Open folder in Finder upon completion of downloads
tell application "Finder"
activate
open BaseDir
end tell
I should highlight that this is not a robust script intended for general use that would work across situations, but rather an example script that is tailored specifically to the case described. If your CSV file differs even slightly from my assumed format, errors are likely to occur.
Here's our situation:
We have a list of file names and/or full file paths (we can generate either)
The files in our list are all contained under one folder, but scattered across multiple sub-folders. (There are hundreds of items in our select list from thousands of possible files. Selecting manually isn't an option)
We've got the root folder open in list view and all sub-folders, sub-sub etc disclosure-opened (btw thanks to http://hints.macworld.com/article.php?story=20030218164922494 for the shortcut "command, option, control and shift when pressing the right arrow")
With all files visible under one window open we want to automatically select all the items in our file list so that they can then be dragged at once to an application.
I do not believe that with basic AppleScript one can programmatically select multiple items in Finder which span throughout different folders and subfolders within a given folder in one window. Maybe with Cocoa-AppleScript, don't know, however if Avid can open files from file aliases, then the following example AppleScript code is a viable option.
The example AppleScript code makes the following assumptions:
There is a plain text file containing the fully qualified POSIX pathnames of the target files to be processed with Avid and the name of the file is: List of Files to Process with Avid.txt
The name of the folder containing the aliases is: Aliases of Files to Process with Avid
The Desktop is used as the location in the filesystem that the aforementioned file and folder exists, to be processed by Avid.
Obviously these settings can be changed as needed/wanted, see the comments in the code.
Example AppleScript code:
-- # Set the value of the following three property variables:
-- #
-- # The value of 'thisLocation' is an colon-delimited path string, e.g. 'path to desktop as string' returns: "Macintosh HD:Users:me:Desktop:"
-- # NOTE: When not using 'path to (folder)' where 'folder' is a 'folder constant' , the special folder for which to return the path, the value should be in the form of an colon-delimited path string.
-- # See: https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW19
-- #
-- # The value of 'theListFilename' is the name of the plain text file containing the fully quilified pathnames of the target files to be opened in Avid.
-- # The value of 'theFolderName' is the name of the temporary folder the temporary aliases will be created in. This folder gets created new each run with new aliases.
-- #
-- # NOTE: For ease of use, as each run is presumed to be temporary to get that job run done, the location of the 'theListFilename' and 'theFolderName' are both in 'thisLocation'.
property thisLocation : (path to desktop as string)
property theListFilename : "List of Files to Process with Avid.txt"
property theFolderName : "Aliases of Files to Process with Avid"
-- # The remaining code is tokenized and should not need to be modified.
tell application "Finder"
if (exists thisLocation & theListFilename) then
tell current application to set theList to read alias (thisLocation & theListFilename)
else
display dialog "The file, \"" & theListFilename & "\", was not found at the expected location." buttons {"OK"} ¬
default button 1 with title "Missing File" with icon 0
return
end if
set theFolderPathname to thisLocation & theFolderName
if not (exists theFolderPathname) then
make new folder at thisLocation with properties {name:theFolderName}
else
move theFolderPathname to trash
make new folder at thisLocation with properties {name:theFolderName}
end if
repeat with i from 1 to length of theList
try
make new alias file at theFolderPathname to POSIX file (paragraph i of theList)
end try
end repeat
reveal theFolderPathname
activate
-- delay 1 -- # In necessary, uncomment and adjust value as appropriate.
select every item of alias theFolderPathname
end tell
In Script Editor, save this script and an application, e.g. Select Files to Process with Avid, and then run as needed after replacing the e.g. List of Files to Process with Avid.txt with the current set of target files to be processed with Avid.
The script does the following:
Checks to see the file e.g. List of Files to Process with Avid.txt exists and if not displays error message and exits.
Checks to see if the folder e.g. Aliases of Files to Process with Avid exist and if not creates it, and if it exists, moves it to the Trash and creates it anew, for the new run of target files to be processed.
Creates an alias of each file listed, as a fully qualified POSIX pathname, in the file e.g.: List of Files to Process with Avid.txt
Opens the folder, e.g. Select Files to Process with Avid, in Finder and selects the aliases.
You are now ready to drag and drop the selected aliases to Avid.
Note: This script assumes the fully qualified POSIX pathnames of the target files to be processes with Avid do not contain linefeeds, carriage returns and or null characters in their pathnames.
This works using the latest version of Sierra.
I was not able to figure out a way to selectively select files in folders with subfolders with subfolders etc. The only solution I was able to come up with was to create folder called “Aliases” and have AppleScript create alias files to all of the ”selected files” and store all of the aliases in the aliases folder. From there you can drag all of the files and drop them into your application as you desired
If you have a plain text file containing POSIX path filenames, each on a separate line like the example in this next image, this version will load the pathnames from the text file directly into the script. Just save this script as an application. You can drag text files directly onto the icon of the app because the code is set up to be a droplet
global theFile
property theInfo : missing value
property theName : missing value
property theList : {}
property theList2 : {}
property aliasFolder : (path to desktop as text) & "Aliases"
on open theFiles
set theInfo to info for theFiles
set theName to POSIX path of theFiles
getLinesofFileAsList(theName)
tell application "Finder"
if not (exists of alias aliasFolder) then
make new folder at (path to desktop as text) with properties {name:"Aliases"}
end if
delete every item of alias aliasFolder
end tell
repeat with i from 1 to count of theList
try
set theResult to POSIX file (item i of theList) as text
set end of theList2 to theResult
tell application "Finder"
set theAliases to make new alias file at aliasFolder to theResult
end tell
end try
end repeat
delay 0.5
tell application "Finder"
activate
delay 0.5
set hmmm to reveal aliasFolder
delay 0.5
set hmmm to select every item of alias aliasFolder
activate hmmm
end tell
end open
on getLinesofFileAsList(theName)
set theFile to theName
set theFile to POSIX path of theName
set theList to read POSIX file theFile as text
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set theList to paragraphs of theList
if last item of theList is "" then
set theList to reverse of rest of reverse of theList
end if
set AppleScript's text item delimiters to saveTID
end getLinesofFileAsList
--on run
-- -- Handle the case where the script is launched without any dropped files
--end run
(This is a new edit from a previous question of mine which achieved -3 votes. Hope this new one has a better qualification)
I need to create an Automator service to organize a high amount of files into folders. I work with illustrator and from each .ai file I create 3 more formats: [name.pdf], [name BAJA.jpg] and [name.jpg], thats 4 files in total
My problem is that during the week I repeat this process to more than 90 different .ai files. So 90 files * 4 is 360 independent files all into the some project folder.
I want to grab all 4 related files into one folder, and set the folder name as the same as the .ai file.
Since all the file names are identical (except one), I thought of telling the finder to grab all the files with the same name, copy the name, create a folder and put this files inside, but I have a file name variant [name LOW.jpg] Maybe I can tell the script to strip that work as an exception.
That way I will all 4 the files unified into one folder.
Thank you in advance
Update: This problem was originally posted back in 2013, now I have a solution. People help me assembled this script to fit my needs.
I added this as a service and assigned a keyboard shurtcut on MacOs.
This is the code:
on run {input, parameters} -- create folders from file names and move
set output to {} -- this will be a list of the moved files
repeat with anItem in the input -- step through each item in the input
set {theContainer, theName, theExtension} to (getTheNames from anItem)
try
# check for a suffix and strip it off for the folder name
if theName ends with " BAJA" then
set destination to (makeNewFolder for (text 1 thru -6 of theName) at theContainer)
else
set destination to (makeNewFolder for theName at theContainer)
end if
tell application "Finder"
move anItem to destination
set the end of the output to the result as alias -- success
end tell
on error errorMessage -- duplicate name, permissions, etc
log errorMessage
# handle errors if desired - just skip for now
end try
end repeat
return the output -- pass on the results to following actions
end run
to getTheNames from someItem -- get a container, name, and extension from a file item
tell application "System Events" to tell disk item (someItem as text)
set theContainer to the path of the container
set {theName, theExtension} to {name, name extension}
end tell
if theExtension is not "" then
set theName to text 1 thru -((count theExtension) + 2) of theName -- just the name part
set theExtension to "." & theExtension
end if
return {theContainer, theName, theExtension}
end getTheNames
to makeNewFolder for theChild at theParent -- make a new child folder at the parent location if it doesn't already exist
set theParent to theParent as text
if theParent begins with "/" then set theParent to theParent as POSIX file as text
try
return (theParent & theChild) as alias
on error errorMessage -- no folder
log errorMessage
tell application "Finder" to make new folder at theParent with properties {name:theChild}
return the result as alias
end try
end makeNewFolder
Hope this helps.
It's a pity you get downvoted as I, personally, enjoy answering these sorts of questions, as it helps me practise and improve my own skills.
Thanks for posting your solution. I think it's a great gesture and others will find it useful.
This script is a bit shorter than and uses "System Events" instead of "Finder", so will be quicker for large numbers of files:
set IllustratorOutputFolder to "/Users/CK/Desktop/example"
tell application "System Events" to ¬
set ai_files to every file in folder IllustratorOutputFolder ¬
whose name extension is "ai"
set Output to {}
repeat with ai_file in ai_files
set AppleScript's text item delimiters to "."
get name of ai_file
get text items of result
set basename to reverse of rest of reverse of result as text
tell application "System Events"
get (every file in folder IllustratorOutputFolder ¬
whose name begins with basename)
move result to (make new folder ¬
in folder IllustratorOutputFolder ¬
with properties {name:basename})
end tell
set end of Output to result
end repeat
return Output -- list of lists of moved files
Just an alternative way of doing things. Not that it's better or worse, but just a different solution.
You could also save this as script.sh (in TextEdit in plain text mode) and run it with bash script.sh in Terminal:
cd ~/Target\ Folder/
for f in *.ai *.pdf *.jpg; do
dir=${f%.*}
dir=${dir% LOW}
mkdir -p "$dir"
mv "$f" "$dir"
done
I'd like to create an automator action to help manage DNG/XMP files. I'd like to be able to drag a DNG (or several) onto the action which will send the DNG and the matching XMP file to the trash. The files have the same name except for the extension, they are in the same directory. For example, IMGP1361.DNG and IMGP1361.xmp
This would be a simple task for a shell script, but is there an Automator way to do it (to learn more about Automator)? Is there a way to get at the file name of the input finder item, change it in a variable and use that as input to another action?
Thanks.
This script for Automator will delete all of the files that share the same prefix and whose name extension is listed in the grep command. You may add additional extensions as well. (xmp|DNG|pdf|xls)
on run {input, parameters}
try
repeat with anItem in input
tell (info for anItem) to set {theName, theExt} to {name, name extension}
set shortName to text 1 thru ((get offset of "." & theExt in theName) - 1) of theName
tell application "Finder"
set parentFolder to parent of anItem as alias
set matchList to every paragraph of (do shell script "ls " & POSIX path of parentFolder & " | grep -E '" & shortName & ".(xmp|DNG)'")
delete (every file of parentFolder whose name is in matchList)
end tell
end repeat
end try
end run
OK, got it. You can use the AppleScript given below inside an Automator workflow like this:
For every selected file in the Finder, if its extension is in ext_list, it will be moved to the Trash, and so will all other files of the same name in the same folder whose extension is one of those in also_these_extensions.
It can be useful, e.g. also for cleaning a folder with auxiliary LaTeX files: just put "tex" into ext_list and all the other extensions (such as "aux", "dvi", "log") into also_these_extensions.
The selected files don't need to be inside the same folder; you can also select several items in a Spotlight search results window.
on run {input, parameters}
-- for every item having one of these extensions:
set ext_list to {"dng"}
-- also process items with same name but these extensions:
set other_ext_list to {"xmp"}
tell application "Finder"
set the_delete_list to {}
set delete_list to a reference to the_delete_list
-- populate list of items to delete
repeat with the_item in input
set the_item to (the_item as alias)
if name extension of the_item is in ext_list then
copy the_item to the end of delete_list
set parent_folder to (container of the_item) as alias as text
set item_name to text 1 thru ((length of (the_item's name as text)) - (length of (the_item's name extension as text))) of (the_item's name as text)
repeat with ext in other_ext_list
try
copy ((parent_folder & item_name & ext) as alias) to the end of delete_list
end try
end repeat
end if
end repeat
-- delete the items, show info dialog
move the_delete_list to the trash
display dialog "Moved " & (length of the_delete_list) & " files to the Trash." buttons {"OK"}
end tell
end run