Reputation: 37
I'm a total newbie on Automator and Scripting... I have read a lot of answers to problems a bit similar to mine, but I don't succeed to adapt with Automator + AppleScript.
Here is what I want to do:
When I download a file to a directory /Volumes/Macboot /Downloads
, (yes there is a space in the HDD's name), e.g. statement_EUR_2020-05-01_2020-05-31.pdf
.
I verify if the file is with extension pdf + it contains an IBAN + the name contains "statement".
If the file corresponds, I want to verify the year and month in the name and move it accordingly to the good Google Drive folder:
/Volumes/Macboot /Travail en cours/Google Drive/Company/Comptabilité/**2020**/**05**/Compte Transferwise 1/
Right now, I succeeded to obtain year and month in 2 variables, but I can't find a good way to move the file using variables in the next step in Automator.
Upvotes: 0
Views: 1007
Reputation: 37
I've simplified the process and found a way with AppleScript:
on run {input, parameters}
set theFile to input as text
set yearName to ((characters 34 thru -1 of theFile) as string) --trim first 35
set yearName to ((characters 1 thru -22 of yearName) as string) --trim last 23
set monthName to ((characters 39 thru -1 of theFile) as string)
set monthName to ((characters 1 thru -19 of monthName) as string)
set destinationFolder to ("Macboot :Travail en cours:Google Drive:Company:Comptabilité:" & yearName & ":" & monthName & ":Compte Transferwise 1:Relevé PDF + fichier CSV:" as text)
tell application "Finder"
activate
move theFile to destinationFolder -- use "copy source_file to folder (target_folder as alias)" to copy the files
end tell
set result to {yearName, monthName, theFile, destinationFolder}
return result
end run
Upvotes: 0
Reputation: 3174
The following should work, or at least get you on the correct path. Set the following for variables:
text
variable that holds the month value, as above text
variable that holds the year value, as abovestorage
variable that holds reference to the file you are working onstorage
variable that will hold a reference to the output folderThe first two actions collect the month and year from storage and pass it to the AppleScript action as a list in the input variable. That AppleScript action extracts the values from the list, concatenates them into a path string, and the uses the POSIX File
command to turn that into a file reference. The fourth action stores the file reference in the outputFolder variable.
Note that the fifth action ignores the input from the fourth action. Instead, it recovers the original file specifier (that you will have stored somewhere earlier in the workflow, then sends the file specifier to the Move Finder Items actions, which uses the value stored in the outputFolder variable as its destination.
Upvotes: 2