Is it possible to change the contents of a record?

During the past couple of days I started to pimp my wife’s workflow with DEVONthink Pro using AppleScript, which I sort of learn as I go along. Always nice to let other applications doing the heavy lifting while I only glue things together :smiley:

In a group I create some records for contacts, invoice numbers and case numbers (she is a lawyer, that’s why). The contacts are all just simple text files with distinct names and the contact’s id (from the Contacts macOS application) in it. Like this:

		
set theRecord to create record with {name:einTyp, source:dieID, type:text} in theGroup

If for some reason I need to change the content of the file I delete the record and create a new one. Is there a method to update the source of a record?

You can’t “update the source” of a text file, as it’s not linked data. But it is possible to set the text of a file.

You can easily do this destructively with something like…


tell application id "DNtp"
	set plain text of (item 1 of (selection as list)) to "This text replaces the current contents"
end tell

However, if you are trying to selectively change values, you’d need to do a bit of scraping and that would be dependent on the file’s structure.

Thank you very much, that’s perfect. I only store one value in each file, so no parsing at all (yeah, lazy me).

You’re welcome. :smiley:

I just hit a brick wall. I started this stuff five days ago and on my Mac it works. Unfortunately, I haven’t been able to figure out AppleScript’s paths. My functions - I guess they are called handlers in AppleScripts - are in the same folder as the main scripts, which happen to be a folder in the users home directory. If I replace the full path ( like /Users/username/ with the ~-sign AppleScript won’t load the handler file, complaining about ‘cannot change to type file’. Do I have to tweak every file on its own or is there some way to substitute the respective users home folder in the load script directive?

Sorry for bothering again.

Please post code to inspect, as it’s unclear what you’re specifically referring to.

OK, figured it out, it works with ```
set myHandler to load script file ((path to home folder as string) & “Kanzlei:Scripts:Handler.scpt”)


_____________________________________
Sorry, I forgot:

set myHandler to (load script “/Users/hase//Kanzlei/Scripts/Handler.scpt”)


Thats the current working line of code. I thought I could replace the /Users/hase/ part with the tilde like this:

set myHandler to (load script “~/Kanzlei/Scripts/Handler.scpt”)


But for some reason that doesn't work for me.

Paths in AppleScript are fiddly things, as their are POSIX paths and HFS paths. Which one to use and how it behaves can also be dependent on the application you’re talking to.

I’d suggest reading this: developer.apple.com/library/arc … lders.html

Thank you very much. But “fiddly” might be some understatement. For one part I will need a more versatile UI so today I started looking into AppleScriptObjC and guess what - it gets even fiddlier (if that is even a word). Still, it beats trying to write everything from scratch by a considerable margin, and it’s way easier to learn.

Actually, once you get into AppleScript, you should realize it’s quite simple to learn and incredibly powerful! The idiosyncracies with different applications are no different than learning dialects in language.