Automator Quick Action Help

Looking for an automation where the input would be a folder name, in the example, the folder name that would be entered would be "TR0011144". The action would always look inside the "Test Requests" folder and then it would search for the next level down sub folder (in the example image, folder "TR0011000 - 0011499", then within that folder find the folder entered.


Is this possible? The "search function" within finder would eventually find it, but it takes a really really really long time.


MacBook Air 15″, macOS 14.6

Posted on Sep 10, 2024 1:05 PM

Reply
Question marked as Top-ranking reply

Posted on Sep 11, 2024 7:48 AM

Here is a tested (Sonoma 14.6.1) Automator Quick Action where you right-click on your Test Requests folder and a prompt appears asking for the TR00nnnnn folder name to search. As written, the Run Shell Script then outputs the full path of that located (e.g. TR0011144) folder to a Desktop report.txt file.


Replacement Source for the default Run Shell Script:

: <<"COMMENT"
As a Quick Action, one right clicks on the Test Requests folder and is prompted to enter the TR00nnnnn subfolder to locate. The full path of the Test Results folder is passed into the Run Shell Script (e.g. $1) and then the aprompt shell function fires asking for the TR00nnnnn folder to search. These arguments are specified in the UNIX find command that returns the full path to the TR00nnnnn folder if found or zero if not found.
COMMENT

RequestFolder="${1}"

# roll own text prompt as Automator's opens in left lower screen
function aprompt () {
	/usr/bin/osascript <<AS
	use scripting additions

	set x to text returned of (display dialog "Enter TR00nnnnn subfolder to search:" default answer "") as text
	return x
AS
}
SearchFolder=$(aprompt)
mx="$(/usr/bin/find "${RequestFolder}" -type d -name "${SearchFolder}")"
[[ ! $mx = 0 ]] || exit 1
print -Dl $mx > ~/Desktop/report.txt


In all fairness, I was not successful in writing a Shortcuts Quick Action. I was passing the Test Requests folder and the TR00nnnn folder name into the Run Shell Script but it never saw both input variables while specifying as arguments.


4 replies
Question marked as Top-ranking reply

Sep 11, 2024 7:48 AM in response to bdrizzo

Here is a tested (Sonoma 14.6.1) Automator Quick Action where you right-click on your Test Requests folder and a prompt appears asking for the TR00nnnnn folder name to search. As written, the Run Shell Script then outputs the full path of that located (e.g. TR0011144) folder to a Desktop report.txt file.


Replacement Source for the default Run Shell Script:

: <<"COMMENT"
As a Quick Action, one right clicks on the Test Requests folder and is prompted to enter the TR00nnnnn subfolder to locate. The full path of the Test Results folder is passed into the Run Shell Script (e.g. $1) and then the aprompt shell function fires asking for the TR00nnnnn folder to search. These arguments are specified in the UNIX find command that returns the full path to the TR00nnnnn folder if found or zero if not found.
COMMENT

RequestFolder="${1}"

# roll own text prompt as Automator's opens in left lower screen
function aprompt () {
	/usr/bin/osascript <<AS
	use scripting additions

	set x to text returned of (display dialog "Enter TR00nnnnn subfolder to search:" default answer "") as text
	return x
AS
}
SearchFolder=$(aprompt)
mx="$(/usr/bin/find "${RequestFolder}" -type d -name "${SearchFolder}")"
[[ ! $mx = 0 ]] || exit 1
print -Dl $mx > ~/Desktop/report.txt


In all fairness, I was not successful in writing a Shortcuts Quick Action. I was passing the Test Requests folder and the TR00nnnn folder name into the Run Shell Script but it never saw both input variables while specifying as arguments.


Sep 10, 2024 3:47 PM in response to bdrizzo

I have just tested a short Zsh shell script that processes all subfolders in the Test Requests folder. It takes a folder such as TR0011000 - 0011499 and creates an array with 500 sequential entries 0011000 - 0011499, and then takes the input TR0011144 string, strips off the TR, and attempts to match 0011144 in the array created for each subfolder. This is far quicker than it sounds.


Upon a match, I construct the full path to the TR0011144 folder. Once that is done, what do you want the script to do with that folder's contents?


This was tested on Sonoma 14.6.1 and only a script run from the Terminal, not yet in Automator or a Shortcut solution.

Sep 11, 2024 3:49 AM in response to VikingOSX

That sounds amazing! Is that something you would be willing to share? Also the structure will always be the same but new folders will be added in the future (meaning new folders added to the list in the first level down from "test requests" will be in groups of 500).


So cool that there is such a great community to help answer questions, or in this case create solutions.

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.

Automator Quick Action Help

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