Automation and email attachments

ProMacUser

Ars Scholae Palatinae
1,012
I've hit a dark, unused corner in my coding knowledge (because it involves scripting), and I am looking for some advice on how to automate this workflow. I'm a professional musician. Our music library at the orchestra has folders of music for us to play each week. Happily, these are next to a copier/scanner, and I made myself a google account to send scan emails to. It's great, because I never have to think about where my music is. It's in my folder. But it's also in forScore at home and on my iPad.

What I would like to have happen is for the mac that receives the PDF emails from the copier (from the same email every time) to import them automatically into forScore. Here's the workflow:

1. Receive email from [REDACTED COPIER ADDRESS]
2. Run an applescript that copies the attachment to forScore
3. Profit (but not really, because I work for a non-profit, which means there are never any guarantees about anything)
 

cpk0

Ars Tribunus Militum
2,390
Subscriptor++
This isn't a complete solution, but hopefully it points you in the right direction. In Mail.app you would create a rule to find messages coming from the copier address, and the rule's action would be to run an AppleScript, which is one of the default options. AppleScript support in Mail.app will give you access to the message and various properties of the message, including attachments, and the attachments will respond to the "save" command, which will let you save the file to your drive. From there it will depend on some specifics of forScore that I'm not familiar with. If forScore can watch a folder for new files, that could work. It if supports AppleScript or Automator to add new files, that could be an option as well.
 

ProMacUser

Ars Scholae Palatinae
1,012
Thanks, cpk0. Sounds like it's going to be a two-part solution because mail only will respond with an applescript. It would be nice to be able to run a shortcut. I'm going to google this, but can Shortcuts be attached to a folder like Automator folder actions? forScore has an import shortcut which looks like it will work if I can attach it to a folder.
 

ProMacUser

Ars Scholae Palatinae
1,012
Thanks for the help so far everybody. It appears you can do this solely in AppleScript, but debugging is a humongous pain. I am stuck on this step, and no matter what I try, the pdfs are ONLY opening in their default app.

AppleScript:
    tell application "Finder"
        set theFiles to get items of alias temporaryLocation
        repeat with theFile in theFiles
            tell application "forScore" to open theFile
        end repeat
    end tell

Here's the output for that (it seems to be ignoring the nested tell):

Code:
tell application "Finder"
    get every item of alias "Macintosh HUsers:[REDACTED]ocuments:[REDACTED] Scans:Not Imported:"

    open document file "mozartiana.pdf" of folder "Not Imported" of folder "[REDACTED] Scans" of folder "Documents" of folder [REDACTED] of folder "Users" of startup disk

    open document file "prokpno3bsn2.pdf" of folder "Not Imported" of folder "[REDACTED] Scans" of folder "Documents" of folder [REDACTED] of folder "Users" of startup disk

end tell
 

ProMacUser

Ars Scholae Palatinae
1,012
I gave up and did the second part through a automator workflow.

Here's the final rundown:

1. Email comes in and triggers an applescript in mail
2. The script copies any attachments to a temporary folder with a folder action installed through automator
3. Automator runs ANOTHER script that simply opens the files in forScore and then moves them into a final folder
4. BONUS: forScore sends to my other devices in the cloud.

Thanks again, but I am sure we will revisit this, as it seems incredibly fragile.
 
  • Like
Reactions: jaberg