Reading Quicksilver Tags.

Having just started to use Tags with Quicksilver I’d like to display the Tags I’ve already used on my desktop with GeekTool. http://projects.tynsoe.org/en/geektool/doc.php

I’ve found where Quicksilver stores the Tags and I’ve got a basic command to get the Tags out of the file but I could do with some help removing the extra text.

I think I need to do a repeat using Text Delimiters. I’ve looked a the MacScripter tutorial but I can’t get my head round them!!

Here’s the code I’ve got so far:


do shell script "grep string /Users/username/Desktop/QSPresetQSFileTagsPlugIn.qsindex | awk {'print $1'}"

set theTags to result

set newText to switchText of theTags from "<string>qs.tag.file</string>" to ""

to switchText of currentText from SearchString to ReplaceString -- the handler
	
	set storedDelimiters to AppleScript's text item delimiters
	-- this simply stores the current value of AppleScript's AppleScript's text item delimiters
	-- so they can be restored later (thus helping to avoid potential problems elsewhere).
	-- Remember, we always set them back to what they were.
	
	set AppleScript's text item delimiters to SearchString
	-- AppleScript's AppleScript's text item delimiters are now set to "Purple"
	
	set currentText to currentText's text items -- note we have changed currentText's value
	-- create a list of text items from the original text, separated at the points where the
	-- current text item delimiter ("Purple") appeared.
	--> {"What, ", " Shoes?"} - Note that the spaces and punctuation are retained.
	
	set AppleScript's text item delimiters to ReplaceString
	-- AppleScript's AppleScript's text item delimiters are now set to "Green"
	
	set currentText to currentText as Unicode text
	-- coerce the list  {"What, ", " Shoes?"} to Unicode text. This operation will also 
	-- insert the current value of AppleScript's AppleScript's text item delimiters ("Green")
	-- between each of the listed items
	
	--> "What, Green Shoes?"
	
	set AppleScript's text item delimiters to storedDelimiters
	-- restore the value of AppleScript's AppleScript's text item delimiters
	-- to whatever they were on entering the subroutine. Remember that a call to this
	-- might have been made from within a section of script that had the TIDs set to
	-- something else. Hand the result back with the TIDs as they were.
	
	currentText
	-- return the now modified text (and restored TIDs) -- "What, Green Shoes?"
	
	
	set this_text to currentText
	
	set new_text to ""
	
	--Loop through paragraphs of old text
	repeat with myPara in paragraphs of this_text
		--Check for paragraph's contents in new text
		--If not there add new text to end of new text
		if new_text does not contain myPara then set new_text to new_text & myPara & return
	end repeat
	--Remove final return 
	set new_text to (characters 1 thru -2 of new_text) as text
	
end switchText -- the end of the handler.

The result of the script is:

“guides
scripts
Guide”

I’d like to remove the and from the result.

Any ideas how?

Model: iMac
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

I don’t use tags with QuickSilver… didn’t even know about them to be honest, but couldn’t you do something like this maybe?

repeat with myPara in paragraphs of this_text
	--Check for paragraph's contents in new text
	--If not there add new text to end of new text
	if new_text does not contain myPara then set new_text to new_text & (text 9 thru -10 of myPara) & return
end repeat

Cheers James

Works a treat!

Thanks.

Is it possible to sort the output so that all the tags are shown alphabetically from Geektool?

Yep, change

do shell script "grep string " & (quoted form of POSIX path of QuicksilverTags) & " | awk {'print $1'}"

to:

do shell script "grep string " & (quoted form of POSIX path of QuicksilverTags) & " | awk {'print $1'} | sort"

Great!
Thank you very much :slight_smile: