I’m having an issue using AppleScript to send a web document to a specific group/folder. The code below is from a larger AppleScript where I am gathering all the links from the front web browser and sending those links to DEVONthink. In my script, I ask for a user inputted group name, and I am trying to have all the inputted links show up in a group/folder name (inside the inbox) that is created from the user input.
At the moment, I am not able to get this to work. I hard-coded a group name “testgroup” into the code and would expect all the links to show up in a folder titled “testgroup” in the DEVONthink inbox. Instead, the individual links are showing up in the inbox, but not within a group folder.
Any tips or suggestions for getting this to work are greatly appreciated.
tell application "DEVONthink 3"
repeat with theURL in tabURLs
create web document from theURL in "testgroup"
end repeat
end tell
I guess @themarkus wants to also create a new group from the user’s input if necessary.
If so then create location could be used:
Note: I’m using a database’s incoming group here, not sure whether
meant the global inbox or a database’s incoming group.
tell application id "DNtp"
try
set theUserInput to "testgroup"
set theDatabase to database "_temp"
set theIncomingGroup to incoming group of theDatabase
if theUserInput contains "/" then -- in this case we need to escape "/"
set theUserInput to my replace_String(theUserInput, "/", "\\/")
end if
set theGroup to create location (location of theIncomingGroup) & (name of theIncomingGroup) & "/" & theUserInput in theDatabase
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
on replace_String(theText, oldString, newString)
local ASTID, theText, oldString, newString, lst
set ASTID to AppleScript's text item delimiters
try
considering case
set AppleScript's text item delimiters to oldString
set lst to every text item of theText
set AppleScript's text item delimiters to newString
set theText to lst as string
end considering
set AppleScript's text item delimiters to ASTID
return theText
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't replaceString: " & eMsg number eNum
end try
end replace_String
It’s probably easier to use display group selector:
tell application id "DNtp"
try
set theGroup to display group selector
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
Or display group selector with the scope set to e.g. the global inbox:
tell application id "DNtp"
try
set theGroup to display group selector for inbox
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
I was trying to save to the Global Inbox without really knowing how the databases and global inbox were structured. With your input, I was able to get myself a bit more familiarized with how applescripting for DEVONthink works.