Skip to content

Instantly share code, notes, and snippets.

@ROldford
Created April 18, 2013 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ROldford/5412692 to your computer and use it in GitHub Desktop.
Save ROldford/5412692 to your computer and use it in GitHub Desktop.
A TaskPaper script to edit tag values. Check out http://www.hogbaysoftware.com/wiki/EditTagValues for more info.
(*
Tag Value Editor script
by Ryan Oldford
Uses handlers from MacScripter forum users (see below for full credits)
This script is used to make it easier to edit tag values in TaskPaper.
The script reads all tags for the current entry, lets the user choose
the tag they will edit, lets the user write the new tag value, then
updates the tag value.
Settings:
useQuicksilver - used when this script is called from Quicksilver (i.e. using a trigger)
messageForNoValues - used to determine if a message is given when no tags have values
*)
property useQuicksilver : false
property messageForNoValues : true
tell application "TaskPaper"
tell selected entry
-- START - Get list of tags with values and list of tag values
set tagsNameList to {}
set wantedTagsNameList to {}
set wantedTagsValueList to {}
set theTags to every tag
repeat with aTag in theTags
if ((value of aTag) exists) then
copy (name of aTag) to tagName
copy (value of aTag) to tagValue
copy tagName to end of wantedTagsNameList
copy tagValue to end of wantedTagsValueList
end if
end repeat
-- END
-- START - Get user to choose 1 tag
if useQuicksilver then activate application "Quicksilver"
if wantedTagsNameList is {} then
if messageForNoValues is true then
display dialog "No tags with values for this entry"
end if
else
if ((length of wantedTagsNameList) is equal to 1) then
set onlyEntry to item 1 of wantedTagsNameList
set theChoice to {}
copy onlyEntry to end of theChoice
else
set theChoice to choose from list wantedTagsNameList with title "Choose tag" with prompt "Choose a tag to edit" with empty selection allowed
end if
-- END
-- START - Get user to edit tag value
if (theChoice is not false) then
set chosenTagName to first item of theChoice
set choiceNumber to my list_position(chosenTagName, wantedTagsNameList)
set chosenTagValue to item choiceNumber of wantedTagsValueList
try
set userCancelled to false
set dialogPrompt to "Enter new tag value for @" & chosenTagName
set changeResult to display dialog "Enter new tag value" default answer chosenTagValue with title "Edit tag value"
on error number -128
set userCancelled to true
end try
-- END
-- START - Update tag value with new value
if userCancelled is false then
set newTagValue to text returned of changeResult
set chosenTag to tag named chosenTagName
set value of chosenTag to newTagValue
-- END
end if
end if
end if
if useQuicksilver then activate application "TaskPaper"
end tell
end tell
on list_position(this_item, this_list)
-- by Apple via Rob on MacScripter (http://macscripter.net/viewtopic.php?pid=26601#p26601)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end list_position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment