Hi all
reading the Devonthink library i understand you can get a 0 - 7
index for the label state.
I cant seem to find how to translate the number to an actual label (TODO
, DONE
etc)
is that possible in anyway?
best
Z
Hi all
reading the Devonthink library i understand you can get a 0 - 7
index for the label state.
I cant seem to find how to translate the number to an actual label (TODO
, DONE
etc)
is that possible in anyway?
best
Z
The label text is not a property of a record in AppleScript.
You could hard code your own values in, e.g., as a simple example…
tell application id "DNtp"
set theRecord to (item 1 of (selection as list))
set recLabel to label of theRecord
if recLabel = 1 then
set labelText to "To Do"
else if recLabel = 2 then
set labelText to "Done"
end if
display alert "Label " & (recLabel & " = " & labelText)
end tell
You can get the descriptions from DEVONthink’s plist
-- Get label descriptions
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
set theLabelDescriptions to my getLabelDescriptions()
on getLabelDescriptions()
if current application's id = "com.devon-technologies.think3" then
set theDefaults to current application's NSUserDefaults's standardUserDefaults()
else
set theDefaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.devon-technologies.think3"
end if
set theDictionary to (theDefaults's dictionaryRepresentation())'s dictionaryWithValuesForKeys:{"LabelDescription-1", "LabelDescription-2", "LabelDescription-3", "LabelDescription-4", "LabelDescription-5", "LabelDescription-6", "LabelDescription-7"}
return theDictionary's allValues() as list
end getLabelDescriptions
Make sure to add the use
statements at the top of your script:
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
Yes, but that is also definitely not a beginner’s solution.
Sure, writting it is not a beginner task. But it’s easy to use.
To create variables for all label descriptions:
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
set {theLabel_1, theLabel_2, theLabel_3, theLabel_4, theLabel_5, theLabel_6, theLabel_7} to my getLabelDescriptions()
--> {"red", "green", "blue", "yellow", "orange", "gray", "black"}
on getLabelDescriptions()
if current application's id = "com.devon-technologies.think3" then -- https://forum.latenightsw.com/t/storing-persistent-values-in-preferences/864
set theDefaults to current application's NSUserDefaults's standardUserDefaults()
else
set theDefaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.devon-technologies.think3"
end if
set theDictionary to (theDefaults's dictionaryRepresentation())'s dictionaryWithValuesForKeys:{"LabelDescription-1", "LabelDescription-2", "LabelDescription-3", "LabelDescription-4", "LabelDescription-5", "LabelDescription-6", "LabelDescription-7"}
return theDictionary's allValues() as list
end getLabelDescriptions
Or, if one only needs specific labels:
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
set theLabelDescriptions to my getLabelDescriptions()
set theLabel_1 to item 1 of theLabelDescriptions
--> "red"
set theLabel_2 to item 2 of theLabelDescriptions
--> "green"
on getLabelDescriptions()
if current application's id = "com.devon-technologies.think3" then -- https://forum.latenightsw.com/t/storing-persistent-values-in-preferences/864
set theDefaults to current application's NSUserDefaults's standardUserDefaults()
else
set theDefaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.devon-technologies.think3"
end if
set theDictionary to (theDefaults's dictionaryRepresentation())'s dictionaryWithValuesForKeys:{"LabelDescription-1", "LabelDescription-2", "LabelDescription-3", "LabelDescription-4", "LabelDescription-5", "LabelDescription-6", "LabelDescription-7"}
return theDictionary's allValues() as list
end getLabelDescriptions
This is a very subjective opinion.
ASOC is not easy to use for many people, including newbies.
I think using a script is simple regardless of the language it is written in. Modifying it – that’s something else.
Obviously I know where the values are stored and how to access them programmatically (though I would not opt for ASOC to do it.)
The OP is expressing an interest in learning to script on their own. Given that parameter, I opted to provide a simple and understandable way to approach the issue to help encourage and teach something.
So the OP now has a choice of worlds; DEVONthink itself is an app which allows users to choose their own route to achieving their goal. Why not do the same in the forum?
I’m not the OP; I don’t even have any need for what the OP is requesting. But I love seeing the different approaches presented here; @pete31’s solution just goes to show me how much more powerful AS(OC) is than I am aware. Nothing wrong with that, Jim - well not as I see it, anyway
I hardcode a list variable
set theLabelDescriptions to {" ",“Pending”, “Active”, “Next Action”, “xCompleted”, “SomedayMaybe”, “”, “Dropped”}
To access
set theLabel to item (label of theRecord + 1) of theLabelDescriptions
thx all!
as @BLUEFROG said im an absolute newb so @BLUEFROG’s code was very easy to understand and implement.
I do appreciate the alternative approach @pete31, i learned some more from it!
thx again guys!
Z
You’re welcome.