Can Automator do this?

Hi

I'm a composer and work every day in my studio. Here I use hardware and software from Universal Audio (UA). The make a LOT (!) of wonderful plug-ins for audio. Every time I update the driver software for my UA hardware I also have to download and install all the new plug-ins they offer, but of course they will only work if I buy them!

So every time I want to use one of the plug-ins that I actually own, I have to scroll down an ever growing list of names to find the one I want!

Now I wonder if I can make an Automator workflow, that will take all the UA file names from my components folder and compare each one with a list - yes a list with the names of the plug-ins that I own - and mark all the files that are on the list/that I own, with the color red? In that way it would be easy simply to delete all the plug-in files that I do not own, and save me endless scrolling.

I don't expect a finished workflow but a - "go look there" would be very nice.


Best Regards

Stig Christensen MUSICMIND

Mac Pro

Posted on Jan 7, 2021 12:25 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 8, 2021 6:23 AM

From your Dock, click Launchpad, and on the first screen, look for the Other item, and click it. Click on the Automator icon located there.


  1. Automator will open a File chooser, and you want to select New Document at the bottom of that panel, and a new panel will appear of the Automator categories. Choose Application, and then click Choose.
  2. Automator will now present a list of libraries containing action in its left panel, and the center area is the workflow region where you will drag and drop selected actions in order:
    1. Files & Folders Library : Ask for Finder Items
    2. Utilities Library : Run Shell Script
  3. You should now have two actions in your workflow window. So let's configure them:
    1. Ask For Finder Items
      1. Start at: Desktop
      2. Type: Folders
      3. Allow Multiple Selection remains unselected
    2. Run Shell Script
      1. Shell: /bin/zsh
      2. Pass input: as arguments
      3. Completely remove the default for loop from this action, as you will replace it with the script provided below
  4. Save your Automator Application to your Desktop with a short but meaningful name of your choosing. No extension is necessary.
  5. Quit Automator


Script (copy/paste into Automator Run Shell Script action above)


#!/bin/zsh

: <<-COMMENT

Compare list of owned component names to names of all component files downloaded
into the current directory location. Using list intersection, apply a red tag to
each owned (common) file in the directory.

COMMENT

zmodload zsh/mapfile

function tag_file () {
    osascript <<-AS
      use framework "Foundation"
      use AppleScript version "2.4"
      use scripting additions

      property NSURL : a reference to current application's NSURL
      property NSURLTagNamesKey : a reference to current application's NSURLTagNamesKey

      set taglist to {"${2}"}
      set tURL to NSURL's fileURLWithPath:"${1}"
      tURL's setResourceValue:taglist forKey:NSURLTagNamesKey |error|:(reference)
      return
AS
}

# always present a full path to the script
FOLDER="${@:a:s/\~\//}"
OWNED="owned.txt"
# use empty "" quotes to remove tags
TAGNAME="red"

# create three regular arrays for components owned, all component names in the folder,
# and the intersection (common) component names to be tagged
typeset -a compown=() filelist=() tagged=()

# filename containing list of owned components
FNAME=${FOLDER}/${OWNED}
# read owned components names from FNAME text file into an array
compown=( "${(f)mapfile[$FNAME]}" )

# generate an array of installed components names where (^F) only
# uses the folder names matching the UAD* pattern.
cd "${FOLDER}"
filelist=( UAD*.component(^F) )

# array intersection showing owned components whose folder names are to be tagged
tagged=( ${filelist:*compown} )

for f in ${tagged}
do
    # any standard or custom tag name can be used here
    tag_file "$f" $TAGNAME
done
exit 0


Double-click the new Automator application on your Desktop to launch it. A prompt will appear where you choose the folder containing your UAD component folders. That folder path will be passed into the Run Shell Script and any file that appears in the owned.txt file within the folder you selected, will then receive a "red" tag.

24 replies
Question marked as Top-ranking reply

Jan 8, 2021 6:23 AM in response to stigc56

From your Dock, click Launchpad, and on the first screen, look for the Other item, and click it. Click on the Automator icon located there.


  1. Automator will open a File chooser, and you want to select New Document at the bottom of that panel, and a new panel will appear of the Automator categories. Choose Application, and then click Choose.
  2. Automator will now present a list of libraries containing action in its left panel, and the center area is the workflow region where you will drag and drop selected actions in order:
    1. Files & Folders Library : Ask for Finder Items
    2. Utilities Library : Run Shell Script
  3. You should now have two actions in your workflow window. So let's configure them:
    1. Ask For Finder Items
      1. Start at: Desktop
      2. Type: Folders
      3. Allow Multiple Selection remains unselected
    2. Run Shell Script
      1. Shell: /bin/zsh
      2. Pass input: as arguments
      3. Completely remove the default for loop from this action, as you will replace it with the script provided below
  4. Save your Automator Application to your Desktop with a short but meaningful name of your choosing. No extension is necessary.
  5. Quit Automator


Script (copy/paste into Automator Run Shell Script action above)


#!/bin/zsh

: <<-COMMENT

Compare list of owned component names to names of all component files downloaded
into the current directory location. Using list intersection, apply a red tag to
each owned (common) file in the directory.

COMMENT

zmodload zsh/mapfile

function tag_file () {
    osascript <<-AS
      use framework "Foundation"
      use AppleScript version "2.4"
      use scripting additions

      property NSURL : a reference to current application's NSURL
      property NSURLTagNamesKey : a reference to current application's NSURLTagNamesKey

      set taglist to {"${2}"}
      set tURL to NSURL's fileURLWithPath:"${1}"
      tURL's setResourceValue:taglist forKey:NSURLTagNamesKey |error|:(reference)
      return
AS
}

# always present a full path to the script
FOLDER="${@:a:s/\~\//}"
OWNED="owned.txt"
# use empty "" quotes to remove tags
TAGNAME="red"

# create three regular arrays for components owned, all component names in the folder,
# and the intersection (common) component names to be tagged
typeset -a compown=() filelist=() tagged=()

# filename containing list of owned components
FNAME=${FOLDER}/${OWNED}
# read owned components names from FNAME text file into an array
compown=( "${(f)mapfile[$FNAME]}" )

# generate an array of installed components names where (^F) only
# uses the folder names matching the UAD* pattern.
cd "${FOLDER}"
filelist=( UAD*.component(^F) )

# array intersection showing owned components whose folder names are to be tagged
tagged=( ${filelist:*compown} )

for f in ${tagged}
do
    # any standard or custom tag name can be used here
    tag_file "$f" $TAGNAME
done
exit 0


Double-click the new Automator application on your Desktop to launch it. A prompt will appear where you choose the folder containing your UAD component folders. That folder path will be passed into the Run Shell Script and any file that appears in the owned.txt file within the folder you selected, will then receive a "red" tag.

Jan 8, 2021 5:51 AM in response to VikingOSX

In testing, I created the five folder names as your image indicated, and placed three of these names in the owned.txt file:

UAD AMS RMX16 Expanded.component
UAD AMS RMX16.component
UAD Ampex ATR-102.component


And when I run the script from the Terminal command line providing the folder name as a command-line argument, the three component folder names from the owned.txt file were tagged red:



Finder Preferences : Tags panel allows you to create your own custom tag names, and assign them a color, so you could have an owned custom tag that is red, and instead of using "red" in the script, you could use "owned" and that would appear in the tag column instead of the word red.


I still need to package this up in an Automator script and test that, but shouldn't take much longer (this morning).

Jan 7, 2021 4:25 PM in response to stigc56

I just put together a script that reads the contents of a text file containing selected filenames found in a specified folder, into an array, and then I read all filenames in that folder into another array. When I intersected the arrays, the files from the list, that matched the files from the folder were written to a third array.


When I looped through that third array of files to be tagged, each file was then tagged with the tag name "red" and these appeared in a finder view of that folder.


This is not written to operate on a folder hierarchy, and I would need to know the naming convention for the UA file names in your components folder. But at least the logic appears to be working here.

Jan 8, 2021 4:03 AM in response to stigc56

Do the UAD filenames all have the same filename extension, and what is that extension? I can have Automator prompt you for the folder containing your UAD components and pass that folder path to the script. There needs to be a text file (let's call it owned.txt), in that folder, which contains the single-column, list of filenames of all of your currently owned components.


Given the above information, the script has what it needs to tag the owned files in your selected folder. The assumption is that the owned.txt file and all UAD component files are contained in a single directory, and not in sub-directories of the selected folder. Once I have the above information, I will test again here, and then post the script and the instructions on how to construct an Automator application.



Jan 10, 2021 5:15 AM in response to stigc56

The script expects to receive the name of the folder actually containing your components, so Documents : Plug-ins would not work, but choosing Documents : Plug-ins : components, (or the real name of that component folder) where the actual UAD*.components are located, would allow the script to see your owned.txt file, the UAD*.components, and process as expected.


That owned.txt file needs the full filename and component extension, as shown here:

UAD AMS RMX16 Expanded.component
UAD AMS RMX16.component
UAD Ampex ATR-102.component


Also, make one small change to the script code:


From:

# generate an array of installed components names where (/) only
# uses the folder names matching the UAD* pattern.
cd "${FOLDER}"
filelist=( UAD*.component(^F) )


To:

# generate an array of installed components names where (/) only
# uses the folder names matching the UAD* pattern.
cd "${FOLDER}"
setopt kshglob
filelist=( UAD*.component(/) )


This change made no difference in the script working correctly here, but it is syntactically better.

Jan 9, 2021 7:08 AM in response to stigc56

I just copied the code that I posted above into a new Automator application, and when ran, it applied red tags to the three files contained in the owned.txt file.


Does your Automator application look like the following before you saved it? You can right-click on the following image and open it in a new browser window where it can be enlarged for clarity:


Jan 9, 2021 4:26 AM in response to VikingOSX

Hi again

First of, thank you a lot for your help so far!

I have done what you suggested, but I get the same error every time I run the Automator program:

Translated: The action "Start Shell-instruks" met an error: .....


This is the first 3 lines in my owned.txt file looks like this:


UAD Ampex ATR-102.component

UAD AMS RMX16 Expanded.component

UAD AMS RMX16


Any idea what went wrong?


Jan 10, 2021 4:29 AM in response to VikingOSX

Hi again!

Just posted a reply with a link to my dropbox with the folder, containing the plug-ins AND the owned.txt file.

This was rejected by a moderator. So I'll try again:


Sadly it doesn't work even after the instructions you send!

To be clear:

The Automator App is on my Desktop. The Plug-Ins folder and the owned.txt file is in the same folder placed in my documents folder. I run the App from the Desktop, select the folder with my plug-ins AND the owned.txt file, and I get this:


Appreciate your help!

Jan 12, 2021 6:58 AM in response to VikingOSX

Can I ask you a supplementary question?

I want to create two Automator apps. One that takes care of the .component files and one that handles the .vst files.

When I load the Automator app from the desktop into the Automator Editor and try to save under another name I get a FOLDER, not an app.

What is the right way to do this?

Can you refer to YT videos or written material!

Thanks a lot for your help!

Jan 12, 2021 8:49 AM in response to stigc56

Launch Automator, ignore the file chooser, and select Open Recent -> the application you saved that processes the .component items. Press the option key and select File menu -> Save As… and give it a different name that you recognize as processing .vst items onto your Desktop with File format Application.


You should now see that as another Automator application icon on your Desktop.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can Automator do this?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.