Hook Mark doesn't work after Bear2 update: No linkable item found in Bear(fixed, please update your script, version 282))

Recently, Bear2 released a new version and found that Hookmark doesn’t work anymore. When calling out, it prompts “No linkable item founåd in Bear”. Hopefully the author can fix it soon. :pray:

I just updated Bear to the latest version :Version 2.0.2 (11749). It seems to be working fine.

May I ask what’s your system language?
Is your Bear’s app name still “Bear” or “Bear2”?

If you run the following script in Script Editor(Select a Bear note first please), what’s the result?

Thank you

Summary
use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use scripting additions

tell application "Bear"
	activate
end tell
on localizedStringFor:keyStr fromTable:stringsFileName inBundle:fileOrNSURL langID:langID
	set theBundle to current application's NSBundle's bundleWithURL:fileOrNSURL
	set sourceURL to theBundle's URLForResource:stringsFileName withExtension:"strings" subdirectory:"" localization:langID
	
	set theData to current application's NSData's alloc()'s initWithContentsOfURL:sourceURL
	if theData is missing value then return ""
	set sourceDict to (current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:0 |error|:(missing value))
	set destValue to sourceDict's objectForKey:keyStr
	return destValue as text
	
end localizedStringFor:fromTable:inBundle:langID:


set theURL to path to application "Bear"
set theBundle to current application's NSBundle's bundleWithURL:theURL

set langStr to ""
try
	set resultText to (do shell script "defaults read net.shinyfrog.bear AppleLanguages")
	set langIDs to {}
	set {TID, text item delimiters} to {text item delimiters, quote}
	set resultItems to text items of resultText
	text item 1 of resultText
	set text item delimiters to TID
	repeat with i from 1 to (count resultItems)
		if i mod 2 = 0 then set end of langIDs to resultItems's item i
	end repeat
	set langStr to first item of langIDs
	
end try


if langStr is missing value or langStr is "" then
	set langStr to first item of (current application's NSLocale's preferredLanguages as list)
end if
set langID to text 1 thru -4 of langStr

set copyNoteStr to my localizedStringFor:"9Yd-YP-rds.title" fromTable:"Main" inBundle:theURL langID:langID
set noteStr to my localizedStringFor:"26M6AC" fromTable:"Bear Widgets" inBundle:theURL langID:langID
if noteStr is "" or copyNoteStr is "" or noteStr is missing value or copyNoteStr is missing value then
	set noteStr to "Note"
	set copyNoteStr to "Copy Link to Note"
end if

set the clipboard to ""
delay 0.2

tell application "System Events" to tell process "Bear"
	click menu item copyNoteStr of menu 1 of menu bar item noteStr of menu bar 1
	delay 0.05
	repeat 50 times -- poll clipboard for ~2.5 seconds
		try
			set theURL to the clipboard
			if theURL is not equal to "" then
				exit repeat
			end if
		end try
		delay 0.05
	end repeat
	
end tell

set noteTlt to current application's NSPasteboard's generalPasteboard's stringForType:"net.shinyfrog.bear.url-name"

return "[" & noteTlt & "](" & theURL & ")"


After experimenting, I changed the system language to English and I can call out the hookmark menu normally and use it normally. And when the system language is Chinese, it will fail.

Running the script gives the following error:

error "“System Events”遇到一个错误:不能获得“menu item \"missing value\" of menu 1 of menu bar item \"笔记\" of menu bar 1 of process \"Bear\"”。" number -1728 from menu item "missing value" of menu 1 of menu bar item "笔记" of menu bar 1 of process "Bear"

Sorry about this issue.

The fix is available in the script with version 282. Please go to Hookmark Preferences window → Update->Check for update to update the script.

Please let us know if there is any problem

Thank you

Thank you very much, it has been tested and fixed

Hello - Unfortunately, it still doesn’t work for me. Is there anything/setting that I might have to do?

macOS 13.5.1
Hookmark 5.1.2 (5457) with Scripts version 293
Bear 2.0.9 (11930)

Edit: more info below

  • system language: English (US) [although I also have other languages including Chinese (Traditional) and Japanese, but they are not set as the primary]
  • If I run the script mentioned earlier in this thread, I got "" as the result.

Sorry about this issue.

Could you please run the following script in Script Editor and let us know the message in the dialog boxes? Also any error message if there is any.

Thank you

Summary
use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use scripting additions


on localizedStringFor:keyStr fromTable:stringsFileName inBundle:fileOrNSURL langID:langID
	set theBundle to current application's NSBundle's bundleWithURL:fileOrNSURL
	set sourceURL to theBundle's URLForResource:stringsFileName withExtension:"strings" subdirectory:"" localization:langID
	
	set theData to current application's NSData's alloc()'s initWithContentsOfURL:sourceURL
	if theData is missing value then return ""
	set sourceDict to (current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:0 |error|:(missing value))
	set destValue to sourceDict's objectForKey:keyStr
	return destValue as text
	
end localizedStringFor:fromTable:inBundle:langID:


set theURL to path to application "Bear"
set theBundle to current application's NSBundle's bundleWithURL:theURL

set langStr to ""
try
	set resultText to (do shell script "defaults read net.shinyfrog.bear AppleLanguages")
	set langIDs to {}
	set {TID, text item delimiters} to {text item delimiters, quote}
	set resultItems to text items of resultText
	text item 1 of resultText
	set text item delimiters to TID
	repeat with i from 1 to (count resultItems)
		if i mod 2 = 0 then set end of langIDs to resultItems's item i
	end repeat
	set langStr to first item of langIDs
	
end try

if langStr is missing value or langStr is "" then
	set langStr to first item of (current application's NSLocale's preferredLanguages as list)
end if
set langID to text 1 thru -4 of langStr
display dialog "langStr: " & langID

set copyNoteStr to my localizedStringFor:"9Yd-YP-rds.title" fromTable:"Main" inBundle:theURL langID:langID
set noteStr to my localizedStringFor:"26M6AC" fromTable:"Bear Widgets" inBundle:theURL langID:langID
if noteStr is "" or copyNoteStr is "" or noteStr is missing value or copyNoteStr is missing value then
	set noteStr to "Note"
	set copyNoteStr to "Copy Link to Note"
end if

set the clipboard to ""
delay 0.2
display dialog "noteStr:" & noteStr
display dialog "copyNoteStr: " & copyNoteStr
tell application "Bear"
	activate
end tell

tell application "System Events" to tell process "Bear"
	click menu item copyNoteStr of menu 1 of menu bar item noteStr of menu bar 1
	delay 0.05
	repeat 50 times -- poll clipboard for ~2.5 seconds
		try
			set theURL to the clipboard
			if theURL is not equal to "" then
				exit repeat
			end if
		end try
		delay 0.05
	end repeat
	
end tell
display dialog "theURL: " & theURL

set noteTlt to current application's NSPasteboard's generalPasteboard's stringForType:"net.shinyfrog.bear.url-name"

return "[" & noteTlt & "](" & theURL & ")"


Hi -

Thanks for reply, and here’s an example:

  • langStr: en
  • noteStr:Note
  • copyNoteStr: Copy Link to Note
  • theURL: bear://x-callback-url/open-note?id=4D9E0EC1-59F9-4B17-BD6C-77028725229F
  • "[<actual note title>](bear://x-callback-url/open-note?id=4D9E0EC1-59F9-4B17-BD6C-77028725229F)" (this last one isn’t from a dialog box, but the Result within the main window)

Although sometimes <actual note title> will be missing values even for the same note.

The script seems to be working fine.

When you said it is not working for you, did you mean you get “No linkable item found in Bear”? Any other error message?

Could you please go to the the following page, and check if the automation is set correctly for Hookmark? You can find related information in section 2. Hookmark’s Automation permission to control the app is effectively disabled

in this web page:

Hello - thanks for the reply.

  • Yes, I get “No linkable item found in Bear” without any other error message showing up. (At least, not that I’m aware of.)
  • I followed the steps from the support page you mentioned. But unfortunately, I’m still not able to use Hookmark in Bear. I wanted to note that, for other apps I’m using with Hookmark, they have been working properly.

One more observation while I tested with the script again, and noticed that there is always a system error sound played after copyNoteStr dialog shows up, and before theURL window becomes available. Also, that theURL window actually won’t popup on its own even after the error sound I mentioned. At this point, the Hookmark app icon on the Dock will be bouncing, and if I click it, the window for theURL will appear.

Thank you for the info, @pol . The error sound is expected because Bear window is activated.

Could you please go to Hookmark preferences window ->Scripts->Bear ->Get address, replace the current one with the following script and click on save button? Then try it again and let us know the output.

You could also try reinstall Bear and see if it solves the problem.

Thank you

Summary
use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use scripting additions


on localizedStringFor:keyStr fromTable:stringsFileName inBundle:fileOrNSURL langID:langID
	set theBundle to current application's NSBundle's bundleWithURL:fileOrNSURL
	set sourceURL to theBundle's URLForResource:stringsFileName withExtension:"strings" subdirectory:"" localization:langID
	
	set theData to current application's NSData's alloc()'s initWithContentsOfURL:sourceURL
	if theData is missing value then return ""
	set sourceDict to (current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:0 |error|:(missing value))
	set destValue to sourceDict's objectForKey:keyStr
	return destValue as text
	
end localizedStringFor:fromTable:inBundle:langID:

try
	set theURL to path to application "Bear"
	set theBundle to current application's NSBundle's bundleWithURL:theURL
	
	set langStr to ""
	try
		set resultText to (do shell script "defaults read net.shinyfrog.bear AppleLanguages")
		set langIDs to {}
		set {TID, text item delimiters} to {text item delimiters, quote}
		set resultItems to text items of resultText
		text item 1 of resultText
		set text item delimiters to TID
		repeat with i from 1 to (count resultItems)
			if i mod 2 = 0 then set end of langIDs to resultItems's item i
		end repeat
		set langStr to first item of langIDs
		
	end try
	
	if langStr is missing value or langStr is "" then
		set langStr to first item of (current application's NSLocale's preferredLanguages as list)
	end if
	set langID to text 1 thru -4 of langStr
	display dialog "langStr: " & langID
	
	set copyNoteStr to my localizedStringFor:"9Yd-YP-rds.title" fromTable:"Main" inBundle:theURL langID:langID
	set noteStr to my localizedStringFor:"26M6AC" fromTable:"Bear Widgets" inBundle:theURL langID:langID
	if noteStr is "" or copyNoteStr is "" or noteStr is missing value or copyNoteStr is missing value then
		set noteStr to "Note"
		set copyNoteStr to "Copy Link to Note"
	end if
	
	set the clipboard to ""
	delay 0.2
	display dialog "noteStr:" & noteStr
	display dialog "copyNoteStr: " & copyNoteStr
	tell application "Bear"
		activate
	end tell
	
	tell application "System Events" to tell process "Bear"
		click menu item copyNoteStr of menu 1 of menu bar item noteStr of menu bar 1
		delay 0.05
		repeat 50 times -- poll clipboard for ~2.5 seconds
			try
				set theURL to the clipboard
				if theURL is not equal to "" then
					exit repeat
				end if
			end try
			delay 0.05
		end repeat
		
	end tell
	display dialog "theURL: " & theURL
	
	set noteTlt to current application's NSPasteboard's generalPasteboard's stringForType:"net.shinyfrog.bear.url-name"
	return "[" & noteTlt & "](" & theURL & ")"
	
on error errStr number errorNumber
	display dialog "error: " & errStr
end try


Hi @bchend - my apologies for the very delayed reply. I just got a chance to finally test the script you mentioned above. It is working now! And I also just removed the few lines of “display dialog” which I assume is there only for debugging purposes.

Thank you so much!