0

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".

Verification of the file

  • 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.

Automator with 2 variables and problem to move file

2 Answers 2

2

The following should work, or at least get you on the correct path. Set the following for variables:

  • monthName: a text variable that holds the month value, as above
  • yearName: a text variable that holds the year value, as above
  • filePath: a storage variable that holds reference to the file you are working on
  • outputFolder: a storage variable that will hold a reference to the output folder

enter image description here

The 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Ted! By your answer I learned how to use 2 variables in a row and the elegant way to output the path. I have successfully made a solution as shown in my answer.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.