Chris Messina Posted October 21, 2020 Share Posted October 21, 2020 I would like to create a Workflow that takes a file selection from Finder (matching com.apple.xcode.compiled-asset-catalog files) and runs each file through the `acextract` executable. I'm completely unfamiliar with bash scripting syntax, so I understand conceptually what needs to happen, but can't figure out how to get Alfred to do what I want. The command I want to execute is: acextract -i $file -o ./$dir ...where $dir would be the .car filename converted to a new directory, but without an extension, i.e. from ./assets.car to ./assets/ Thanks! Link to comment
deanishe Posted October 21, 2020 Share Posted October 21, 2020 5 hours ago, chris said: I would like to create a Workflow that takes a file selection from Finder (matching com.apple.xcode.compiled-asset-catalog files) and runs each file through the `acextract` executable. If you only want it to be available for certain filetypes, you'll need to implement it as a File Action. A Hotkey can pass your script the selected items in Finder, but you'd have to filter them yourself, then. 5 hours ago, chris said: ...where $dir would be the .car filename converted to a new directory, but without an extension, i.e. from ./assets.car to ./assets/ So the “.car filename” is what the variable $file contains? Link to comment
Chris Messina Posted October 21, 2020 Author Share Posted October 21, 2020 10 hours ago, deanishe said: If you only want it to be available for certain filetypes, you'll need to implement it as a File Action. A Hotkey can pass your script the selected items in Finder, but you'd have to filter them yourself, then. Yes, that's how I started: But when I got to writing the script, I got a bit lost. 10 hours ago, deanishe said: So the “.car filename” is what the variable $file contains? Typically when I run the script on the command line, it looks like this: acextract -i "/Downloads/Assets.car" -o "/Downloads/Assets/" "/Downloads/Assets/" is a directory that doesn't yet exist, but is created by acextract. Link to comment
deanishe Posted October 21, 2020 Share Posted October 21, 2020 # filepaths from ARGV for carfile in $@; do # strip file extension dirpath="${carfile:r}" # create directory mkdir -p "$dirpath" /usr/local/bin/acextract -i "$carfile" -o "$dirpath" done This should work in zsh (not bash). Chris Messina 1 Link to comment
Chris Messina Posted October 22, 2020 Author Share Posted October 22, 2020 52 minutes ago, deanishe said: # filepaths from ARGV for carfile in $@; do # strip file extension dirpath="${carfile:r}" # create directory mkdir -p "$dirpath" /usr/local/bin/acextract -i "$carfile" -o "$dirpath" done This should work in zsh (not bash). Hooray! Ok, one more thing since the basics are working (I swear, I'm trying to learn as we go along)... how would I pass the number of files extracted (i.e. the count of the files in the $dirpath) to a notification? I'm completely baffled. I did some research and found a bash script to do the counting, but for the life of me, I can't figure out how to get the count to the notification... # filepaths from ARGV for carfile in $@; do # strip file extension dirpath="${carfile:r}" # create directory mkdir -p "$dirpath" /usr/local/bin/acextract -i "$carfile" -o "$dirpath" # switch to directory cd $dirpath find . -maxdepth 1 -exec echo \; | wc -l done I'm lost when it comes to setting the variables in the Arg and Vars object. Here's what I'd like to put in the notification: Link to comment
deanishe Posted October 22, 2020 Share Posted October 22, 2020 (edited) 12 hours ago, chris said: I'm lost when it comes to setting the variables in the Arg and Vars object. You don’t need to: just use {query}, which is the output of your script. In any case, you can't just use variables you declared in your previous script. Those variables only exist in that script. Alfred doesn't know anything about them. find . -maxdepth 1 -exec echo \; | wc -l This won't work properly. That does print the number of files in the directory, but you don't want that in the loop. If you ran it with multiple input files, you'd end up with three lines of output, not a cumulative total. You need to capture the output, add it to a running total, then print the total at the end. total=0 # filepaths from ARGV for carfile in $@; do # strip file extension dirpath="${carfile:r}" # create directory mkdir -p "$dirpath" /usr/local/bin/acextract -i "$carfile" -o "$dirpath" # no. of files in new directory n=$( ls "$dirpath" | wc -l ) (( total += n )) done # pass total to next workflow element echo -n $total Edited October 22, 2020 by deanishe Link to comment
Chris Messina Posted October 22, 2020 Author Share Posted October 22, 2020 10 hours ago, deanishe said: # pass total to next workflow element echo -n $total Hmm. Seems like I'm still missing something, or that {query} has the output from the `acextract` process. From the console: Passing output 'Extracting: Icon-Production20x20~ipad.png [1mOK[0m Extracting: Icon-Production29x29~ipad.png [1mOK[0m Extracting: Icon-Production40x40~ipad.png [1mOK[0m Extracting: Icon-Production76x76~ipad.png [1mOK[0m [..] Extracting: uploaderTemporaryLines763x8@2x.png [1mOK[0m Extracting: uploaderTemporaryLines763x8@2x.png [1mOK[0m Extracting: uploaderTemporaryLines763x8@2x.png [1mOK[0m 38' to Post Notification This is what the notification shows: How do I just pass the $total count to the notification? Link to comment
deanishe Posted October 23, 2020 Share Posted October 23, 2020 18 hours ago, chris said: How do I just pass the $total count to the notification? Tell acextract to be quiet or redirect its output with /usr/local/bin/acextract -i "$carfile" -o "$dirpath" > /dev/null Thanks for the beer money. I shall be investing it in Guinness. Chris Messina 1 Link to comment
Chris Messina Posted October 23, 2020 Author Share Posted October 23, 2020 33 minutes ago, deanishe said: Tell acextract to be quiet or redirect its output with /usr/local/bin/acextract -i "$carfile" -o "$dirpath" > /dev/null Ah ha! I looked for a way to silence it's output, but it seems to only support (and no quiet mode): input is required Usage: ./acextract [options] -i, --input: Path to input CAR file. -o, --output: Path to output directory. -l, --list: Print content of the CAR file without extracting. -h, --help: Show help message. -v, --verbose: Print more detail. You can use -vv or -vvv for more info. That worked! 🥳 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now