Rename an existing bookmark via AppleScript?

Hello,

Is it possible to use AppleScript to rename an existing bookmark?

I’ve tried getting a bookmark and then setting the name to something new, and also just creating a new bookmark via make bookmark with properties having the same url as an existing, but neither method seems to work. The change is visible within the script, but not in Hook itself (meaning that the existing bookmark retains the old name in Hook, and no new bookmark is created either).

Using set name of (myVar is the url of an existing bookmark), returns “Test”:

tell application "Hook"
	set _mark to make bookmark with data myVar
	if _mark is missing value then
		return "Failed to create bookmark for myVar"
	else
		set name of _mark to "Test"
		return name of _mark
	end if
end tell

Using make bookmark with properties (myVar is the url of an existing bookmark), returns “Test”:

tell application "Hook"
	set _mark to make bookmark with properties {address:myVar, name:"Test"}
	if _mark is missing value then
		return "Failed to create bookmark for myVar"
	else
		return name of _mark
	end if
end tell

Should this be possible, or am I going about it the wrong way? Thanks.

Update:

Actually, I discovered that retrieving the bookmark by url when running another (different) AppleScript does reflect the change, though Hook itself does not.

After closing Hook completely and restarting it, running the script again then returns the old name again.

So it looks like setting the name via script does something, but Hook’s database does not reflect it, and whatever the script does gets reset when Hook’s database is loaded again.

1 Like