How powerful is the Shortcuts application on MacOS?

Hi,
I have used Applescript and to some extent Automator for years but I have ignored Shortcuts. Today I created my first Shortcut that is run from Finder’s QuickAction menu. Now while my new shortcut works it is basically a copy of my Automator workflow where all the heavy lifting is conducted by Applescript.

Searching the web reveals many statements and opinions about Shortcuts and I wonder how powerful the application is. My first thought having tried to find information is that the name Shortcuts is unfortunate as there are to many other uses for the word.

One statement that crops up all the time is that Shortcuts is going to replace both Automator and Applescript. While I can see it replacing Automator I feel that it would have to be very powerful to replace Applescript. For example my new shortcut runs an Applescript that accepts a folder path from the Finder. It then builds a long text string that is a Shell Script for calling the command line tool exiftool which it then runs. This is all conducted within a Try block so the second part of the Applescript parses the error message returned by exiftool and presents it to the user both as a spoken alerts and a dialog box. To do this the code steps through the error message line by line counting the number of lines that contain a certain phrase. So is this the sort of thing that Shortcuts can do without using Applescript .

Here is a copy of my AppleScript for reference :

on run {input, parameters}
	set tfolderpath to POSIX path of input
	--display dialog "AS folderpath is : " & tfolderpath
	try
		#Build exiftool command string
		set cmd to "/usr/local/bin/exiftool  -m -r "
		
		# Store original file name in tag TransmissionReferenec
		set cmd to cmd & "'-XMP:TransmissionReference<Filename' "
		
		# Update the copyright based on the year the image was taken
		set cmd to cmd & "'-copyright<©${CreateDate#;DateFmt(\"%Y\")} Simon Knight All rights reserved.' "
		
		# Store original file name in Adobe (only) XMP tag PreservedFilename
		set cmd to cmd & "'-XMP:PreservedFilename<Filename' "
		
		# Store original file name in tag Title
		set cmd to cmd & "'-XMP:Title<Filename' "
		
		# Store original file name in IPTC tag Objectname
		set cmd to cmd & "'-IPTC:ObjectName<Filename' "
		
		# Start of the rename the files commands using the createdate tag stored in image file
		# Note the -d tag/command is used to format the create date in following path
		set cmd to cmd & "'-FileName<CreateDate' -d "
		
		# Path to image library - modify to library folder.  Note creates sub folders as required
		set cmd to cmd & "/Volumes/Images_Disc_02_Master/TempTestImageUpdated/" -- NOTE NO SPACE AT END!!!
		
		# Next line specifies the sub folders and filename to be used,
		# %Y is four digit year, %m month, %d day %H%M%S are hour minutes seconds,
		# %%f is original filename and %%e is original extension.
		set cmd to cmd & "%Y/%Y_%m/%Y_%m_%d_%H%M%S_%%f.%%e "
		
		set cmd to cmd & tfolderpath
		
		do shell script (cmd)
		say "Copying of image files to library folder is complete."
	on error errormessage
		say "A problem has occured."
		--display dialog "Here is the Error Message " & errormessage
		set tErrorLines to (paragraphs of errormessage)
		set errorCount to count of tErrorLines # number of errors / lines
		
		# Get just the lines containing "already exists
		--set AppleScript's text item delimiters to theSearchString
		--set theTextItems to every text item of tErrorLines
		
		set tPosn to -1
		set duplicates to 0
		set otherErrors to 0
		repeat with i from 1 to number of items in tErrorLines
			set tLine to item i of tErrorLines
			if tLine = "" then exit repeat
			# Search tline for the text "already exists"
			set tPosn to (offset of "already exists" in tLine)
			if tPosn > 0 then
				# attempting to duplicate an image file so just count it
				set duplicates to duplicates + 1
			else
				# an unexpected error
				set tOtherError to tOtherError & tLine & return
				set otherErrors to otherErrors + 1
			end if
			set tPosn to -1
		end repeat
		
		set tMessage to ""
		if duplicates > 0 then
			set tMessage to (duplicates as string) & " image files were not ingested as they already exist in destination folder." & return
		end if
		
		if otherErrors > 0 then
			tMessage = (tMessage & otherErrors as string) & " other errors were reported :" & return & tOtherError
		end if
		say tMessage
		display dialog tMessage
	end try
	return input
end run

best wishes
S

I only use the Shortcuts application when an application doesn’t have AppleScript support, but has donated functions to the Shortcuts application. I feel the Shortcuts run much slower than an equivalent AppleScript would.

On the positive side of things, the Shortcuts application does have AppleScript support and a small dictionary, so I think AppleScript will be around for the foreseeable future, Automator’s future is less secure in my opinion.

1 Like

#Ferrers

Thank you for replying. I had not thought about the speed of execution but it could well be an issue. I was asking more from a position of surprise that some were suggesting that Shortcuts has powerful programming structures similar to those provided by Applescript and other languages. I now suspect that the posters have no idea of what Applescript is capable of.

1 Like