Quantcast
Channel: DEVONtechnologies Community - Latest posts
Viewing all articles
Browse latest Browse all 18275

Bug in AppleScript command "get record at"?

$
0
0

Maybe I should explain some more context.

Because of my bad eyesight, I can’t use the build-in “Move to…” or “Open…” dialogs. The interface is simply to small. So I tried to recreate them using Keyboard Maestros “Prompt with List” action. It has a bigger, more Spotlight/Alfred like interface:

For this reason, I use two AppleScripts (per macro). The first one compiles a list of paths into a multiline string. To support multiple Databases, the Database name becomes the first Path element, followed by the groups and sub groups. To simplify things, I use posix format:

database/group/subgroup/

Here comes the script:

tell application id "DNtp"
	set grpList to {}
	repeat with db in databases
		set end of grpList to (name of db) & "/" & return
		repeat with par in every parent of db
			set thePath to name of db & location of par & name of par & return
			if thePath does not contain "/Papierkorb" and thePath does not contain "/Tags" then
				set end of grpList to thePath
			end if
		end repeat
	end repeat
	grpList as text
end tell

The “grpList” result will be feed into Keyboard Maestros “Prompt with List” dialog, which will return the user selected line to a KM variable “selectedGroupPath”:

The following scipt decomposes the string to its 2 components (database and location) and will finally open the selected group in DEVONthink:

property grp : ""

tell application "Keyboard Maestro Engine"
	set grp to getvariable "selectedGroupPath"
end tell

tell application id "DNtp"
	activate
	set pos to offset of "/" in grp
	set db to characters 1 thru (pos - 1) of grp as string
	set grp to characters pos thru end of grp as string
	if grp is "/" then
		root of database db
	else
		get record at grp in database db
	end if
	set root of viewer window 1 to result
end tell

I felt “get record at grp in database db” should easily get the job done. But because “/” isn’t returning a reference to “root”, I had to workaround this case by returning “root” explicitly in the IF construct above. Not a great deal, but not pretty either.

Thanks.
Jens


Viewing all articles
Browse latest Browse all 18275

Trending Articles