Would it be fairly easy to add a tag to all open windows?

Hello all,

As per the title – I’m wondering if it would be simple to create a script that adds a specific Tag, to all the currently open windows/files?

This would then allow one to call up a Search of all those tagged files, and then run a search through them. As mentioned before, in the absence of a way to search through already open PDF files (as individual windows), this would presumably solve that challenge?

I again spent longer than I needed to, manually working my way through many open windows, looking for a phrase I know I had read recently – so am thinking of a way to speed this process up…

Any thoughts?

Are you referring to documents opened in their own windows (document windows) or documents in document tabs in a window?

Hi Jim, thanks! Documents in their own windows.

I often have between 20-40 of them open at any given time.

You have 20-40 independent windows open at a time? :open_mouth:
Just getting my parameters straight :smiley:

Yip! :smiley:

All different PDFs of articles. I open a bunch revolving around a particular topic, and jump between them as I’m writing…

Here’s a nice and simple approach…

set ot to AppleScript's text item delimiters
tell application id "DNtp"
	if ((count document windows) > 0) then
		set newTags to (text returned of (display dialog "Enter new Tags separated by a semicolon:" & return & " Ex. ad hoc; one; two; Mozart, Amadeus" default answer ""))
		if newTags ≠ "" then
			set AppleScript's text item delimiters to "; "
			set newTags to text items of newTags as list
			set AppleScript's text item delimiters to ot
			
			repeat with thisWindow in (content record of document windows)
				set (tags of thisWindow) to (tags of thisWindow & newTags)
			end repeat
		else
			display alert "No tags entered."
			return
		end if
	else
		display alert "No document windows are open."
	end if
end tell

Many thanks Jim - will give this a go! This will be a huge help!

No problem. Let me know how you get along with it. Cheers!

Works a charm - thanks Jim!

Noice! :wink:
Cheers!

Works in DT3 too! (Love all the solutions in these forums.)

2 Likes