I think there might be no solution yet, but maybe anyone has a workaround. I am trying to set up a Siri shortcut that renames and saves PDFs to an iCloud folder. Everything works fine so far. Now here is the question: is there any chance to add tags to a file in Siri Shortcuts that I select from a pre-populated drop down menu?
Do you have access to ssh on a Mac connected to iCloud? If so, you can back door this via a shell script that calls AppleScript. You will have to experiment on this, because I lost my documentation and I really never use tags/labels. Also, I think Mojave might have broken this?
Syntax is " # file file file" where 1 is orange, 2 is red, 3 is yellow, 4 is blue, 5 is purple, 6 is green and 7 is grey.
osascript - "$@" << EOF
on run argv
set myLabel to (item 1 of argv as number)
repeat with i from 2 to (count of argv)
tell application "Finder"
set theFile to POSIX file (item i of argv) as alias
set label index of theFile to myLabel
end tell
end repeat
end run
EOF
(I have it in isascriopt because I call it (theoretically) from a bash script. I did just test this and while I got an odd error, the label was applied to the test file. Also, note that this uses the old finder label method, so only one label is attached to the file, not multiple tags.)
Hi, thanks for the good advice. I found a solution that works for me.
I save my files now from the iOS devices to a folder in iCloud. I have Siri shortcuts put a string called âtag_[name_of_the_tag]â according to my selection into the file name. When I switch on my Mac, Hazel looks at this temporary folder, tags the file, deletes the âtag_âŚâ part in the file name and stores the file in the correct place.
This sounds very promising. Any chance you could share (a screenshot of) the Hazel settings youâre using? Also, does the tagging shortcut use a âChoose from Listâ action, with a list of options for the âname_of_the_tagâ variable?
I made a short little video, which should help. This may not be the best way to do it, but in this example if I name a file âMy file_taggit_work_.extâ it will get tagged âWorkâ and renamed to âMy file.extâ
If you have only a handful of tags (as Apple seems to assume we do), then it wouldnât be so hard to make a separate Hazel rule for each and every tag. But if you have a couple hundred tags, as I do, then thatâs not going to work.
So, inspired by âAutomators 8: File Automationâ I starting thinking whether there might not be more to get out of Hazel. (Iâm sure Iâm reinventing the wheel hereâŚ). I figured there must be a way to break down the syntax of the the âWorkâ attribute in Hazel (tagit_work, in your example) to have three elements this: âtagitâ âabcâ â_â, so that the matching is agnostic about the âabcâ part. If there were then a way to generate a variable from that string, in each case, and to use that variable as the tag that is used in the âAdd tagsâ action.
VoilĂ !
Hereâs an example: to apply my tag âkeyreferenceâ, then I append to the filename this:
filename_-_keyreference.ext
I then have a Hazel rule that matches the text after the - and then uses that text (âUSETHISâ in the screenshot) to add a tag. Iâve also added a tag âtagconversionâ, just so I can troubleshoot cases where it doesnât work properly. Iâm attaching a screenshot. Hope this is clear! Itâs certainly helping me out.
For the shortcuts selection I use the âmenuâ action, as my hazel rule can only handle one tag per file so far.
Here is the Hazel screenshot (should be clear even if it is in GermanâŚ):
Hazel looks for a PDF file with the respective âTag_âŚâ string in the file name. Then it adds a tag according to this string. It also adds a âSteuerâ tag (Steuer = tax) with the current year. Subsequently it replaces the text âTag_âŚâ with ânothingâ in the file name. A following Hazel rule moves all files in this folder to the standard action folder I use.
With the few tags I use in my file system this works well for me. It would be nice however to have multiple tags per file and also only one Hazel rule that handles them all instead of one rule per tag.
Here is the script I use, run from Hazel as an embedded script with Shell: /bin/bash
This assumes 1) youâve installed https://github.com/jdberry/tag and 2) that your tags are contained in a comma-delimited text file named according to the following convention:
File.pdf (or whatever - the actual file to be tagged)
File.pdf.wftags.txt (containing the tags)
theFile=$1
ext=${theFile##*.}
tagFileName=`basename "$theFile" .$ext`.wftags.txt
if [ -f "$tagFileName" ]
then
theTags=`cat "$tagFileName"`
tag -a "$theTags" "$theFile"
mv "$tagFileName" ~/.Trash/
fi
The shortcut I use to generate the text file has a two stage selection process â first thereâs a
âChoose from Listâ object then the choice from there is presented as the default answer in an âAsk for Inputâ object. Output from that gets written to the text file.
I would be careful with just using _-_ to match, this is a pretty common string in randomly downloaded files. There are 84 files matching that pattern in my home folder, and not one that I named that way. This rule as written will create a lot of random tags that you may not want.
The German syntax for this command is âNamen konfigurierenâ. It should be something like âadjust nameâ or âconfigure nameâ. With this command you can put together a couple of variables to build the new file name.
Thank you. I am unable to pass the composite variable of âfilenameâ + âextensionâ to the Save File action. I wind up just getting a blank text file that saves with the correct name, but not saving the file.
Essentially what I am trying to do is the following:
Open a .pdf from within some app
Select the extension, which takes the filename, and then appends an extension to the filename
Save the file to Dropbox
I am able to get the filename and create the variable, but not then replace the filename and save the .pdf.
That is what it should look like. Tap on the magic variable âshortcut inputâ and select ânameâ to only adjust the name of the file. Then you should be good to go.
Hereâs the workflow. I have it accepting type â.pdfâ. When I select a .pdf file and trigger the shortcut, I select a category tag that I concatenate with the file name and then want to save it with the combined title.