The idea behind a small project I'm working on is to be able to upload a music file and have After Effects pick it up and render it within a video file template I have.
The workflow would be:
Once I upload a new music file to a folder in my iCloud Drive which would be monitored monitored by my iMac. Each new music file triggers an Adobe script which imports the new track to an Adobe After Effects project which exports it to AME and then quits. The music is then moved to another directory.
I've ran in to an issue with passing in a filename to an Adobe script, so to work around this have made a template Adobe script with a placeholder filename (the file path would always be the same) which can be duplicated, have the placeholder filename replaced (via a batch script, though there could be a simpler way of doing it I'd suspect), executed and then deleted.
As a first pass I've been trying to focus on getting the name of new files to the folder, now with mixed success. When running an AppleScript script (.scpt) file attached to the folder I'm able to get the file name displayed and passed to a batch file. The issue now is that it doesn't seem to work with the Automator equivalent.
Code below:
on adding folder items to thisFolder after receiving theseItems
repeat with i from 1 to count theseItems
try
set thisItem to item i in theseItems
set thisItemsInfo to info for thisItem
set thisItemsFileName to quoted form of name in thisItemsInfo
display dialog thisItemsFileName buttons {"Continue"}
do shell script "/Users/jeffolaa/ReplaceName.sh " & thisItemsFileName
end try
end repeat
end adding folder items to
The ReplaceName batch is a single command:
#!/bin/bash
sed -i.bu 's/EDITTHIS/'$1'/' /Users/jeffolaa/Library/Mobile\ Documents/com\~apple\~CloudDocs/Documents/Adobe\ Scripts/AddMusicExport.jsx
So far my Automator workflow looks like so:
All help is very much appreciated!
Best Answer
Note: This answer was written based on the original posting of the question and in particular the first three paragraphs of this answer, sans this note. Since then, the OP has been updated to address what was expressed in the first three paragraphs and they may now seem out of context. However, looking at the edit history of the OP one can see the relevance in context of the original question. They will remain for now until I have the time to make an appropriate edit.
Sorry, but your question is not that well defined and it's not totally clear what actions you added to the Automator Folder Action workflow, sans the obvious Run AppleScript action. Nor is it clear if there are any actions added before or after the Run AppleScript action. Additionally, it's not clear what code is in
/Users/jeffolaa/pointer.sh
or all of what it's doing. Which leads me to believe that just passing thename
of the file topointer.sh
may not be enough. Although without seeing the code inpointer.sh
, at this point only you know.Also, the form of the AppleScript code you've shown in the OP is not the proper form for an Automator Folder Action workflow using a Run AppleScript action. The
on adding folder items
handler is of the type used in an AppleScript script (.scpt) file that is manually assigned to the target folder using the Folder Action Setup... command from the Services context menu in Finder, not Automator, where you need to use theon input
handler in the Run AppleScript action.You also have no error handling code, which is important in Folder Actions and the type and amount can depend on what you have coded in the
pointer.sh
. In other words, you might want to filter the items added to the folder by type, making sure it's a file not a folder, or a particular type of file with a given extension, etc. This can be done in Automator before it gets to the Run AppleScript action, or in the code of the Run AppleScript action, or in the code inpointer.sh
, or a combination of any or all of them.With that said, the following example AppleScript code is a minimal coding of what makes sense to be able to pass the quoted fully qualified pathname of the file(s) added to the target folder you set in Automator's Folder Action receives file and folders added to [folder] to pass to
pointer.sh
, as that's typical of an argument passed to a shell command.Minimal example AppleScript code for use in a Run AppleScript action in an Automator Folder Action workflow:
Minimal example AppleScript code for use in an AppleScript script (.scpt) file manually assigned to the target folder using the Folder Action Setup... command from the Services context menu in Finder:
~/Library/Scripts/Folder Action Scripts
folder that's within your Home folder.To test the above code, I created the
/Users/jeffolaa/pointer.sh
file with the following code in it:Which simply moves the files back to the folder from which they were dragged from to the target folder the Folder Action is assigned to, which is a folder within the Test folder. This let me know it was working properly as coded.
Now if it's just the
name
of the file you want to pass topointer.sh
, you can use the following:Minimal example AppleScript code for use in a Run AppleScript action in an Automator Folder Action workflow:
Minimal example AppleScript code for use in an AppleScript script (.scpt) file manually assigned to the target folder using the Folder Action Setup... command from the Services context menu in Finder:
~/Library/Scripts/Folder Action Scripts
folder that's within your Home folder.To test the above code, I edited the
pointer.sh
file with the following code in it:Which simply says the
name
of the file held inthisItemsFileName
, which let me know it was working properly as coded.Note: The example AppleScript code above is just that, and sans wrapping it in a
try
statement, does not include any other error handling as may be appropriate/needed/wanted, the onus is upon the user to add any appropriate error handling for any example code presented and or code written by the oneself.That said, if you'd update your question to fill in the missing pieces as mentioned in the opening paragraphs of my answer, I'll be glad to edit these code examples to reflect what appropriate error handling should be added. There's just no sense adding it until I know the particulars.