Hook to Endnote Articles

Currently, there is no way to Hook to individual references in Endnote. Anyone know a way that this could be done?

Thanks!

last time we checked Endnote lacked automation.

If Endnote has comments fields, you could paste Hook-garnered links in them.

I implemented this on endnote 20: GitHub - aitsc/endnote-hook

1 Like

Thank you for implementing this!

We will integrate it into Hook.

Welcome to the Hook Productivity Forum , @tsc. Thanks for sharing!

We’ll need to replace the python3 call with some ObjectiveC since Apple unfortunately removed python.

We’ve modified the New Item script because macOS does not have Python anymore

could EndNote users please let us know if the following works for them?

# given hook://endnote/?dn=1-1954,1-2093&l=SCI|Area 3&or=false
# Where dn represents the number of the database opened (starting from 1) - the number of the paper #, ..
# l represents the label to be retrieved, different words are separated by vertical bars |, or if true, it means that the relationship between different words is or for retrieval, the default is false and the relationship
# will not encode the url itself, if dn has a value, the l parameter will be ignored


on path2url(thepath)
	tell current application's NSString to set urlString to stringWithString_(thepath)
	set theDecodedURL to urlString's stringByRemovingPercentEncoding -- 4 is NSUTF8StringEncoding
	return theDecodedURL as Unicode text
end path2url

set fullURL to path2url("$0")

on theSplit(theString, theDelimiter)
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theArray to every text item of theString
	set AppleScript's text item delimiters to oldDelimiters
	return theArray
end theSplit

on intersection(list_list) # 多个list求交集
	local newList, listB, a
	set newList to item 1 of list_list
	repeat with listA in list_list
		set listB to {}
		repeat with a in listA
			set a to contents of a -- dereference implicit loop reference
			if {a} is in newList then set end of listB to a
		end repeat
		set newList to listB
	end repeat
	return newList
end intersection

on union(list_list) # 多个list求并集, 一个list内部重复的元素会去除
	local listA, listB
	set listA to {}
	repeat with listB in list_list
		set listA to listA & listB
	end repeat
	set listB to {}
	repeat with a in listA
		set a to contents of a -- dereference implicit loop reference
		if {a} is not in listB then set end of listB to a
	end repeat
	return listB
end union

set l_or to "false"
if (count of text items of fullURL) is greater than 1 then
	set fragment to item 2 of theSplit(fullURL, "?")
	set AppleScript's text item delimiters to "&"
	set kvs to text items of fragment
	repeat with kv in kvs
		set AppleScript's text item delimiters to "="
		set k to text item 1 of kv
		set v to text item 2 of kv
		if k = "dn" then
			set database_recNum to v
		end if
		if k = "l" then
			set Label to theSplit(v, "|")
		end if
		if k = "or" then
			set l_or to v
		end if
	end repeat
end if

if database_recNum ≠ "" then
	set myResults to {}
	repeat with dr in theSplit(database_recNum, ",")
		set database to item 1 of theSplit(dr, "-")
		set recNum to item 2 of theSplit(dr, "-")
		set end of myResults to "<RecordID database=\"" & database & "\" recNum=\"" & recNum & "\" />"
	end repeat
else
	tell application "EndNote 20"
		set myResults to {}
		repeat with l in Label
			set end of myResults to find l in field "Label"
		end repeat
	end tell
	if l_or = "true" then
		set myResults to union(myResults)
	else
		set myResults to intersection(myResults)
	end if
end if

tell application "EndNote 20"
	activate
	show records in myResults in first window
end tell

error "“NSString” does not understand the “stringWithString_” message. " number -1708 from NSString

1 Like

Sorry. Here is the modified Open item script:

use framework "Foundation"
# 链接例子为 hook://endnote/?dn=1-1954,1-2093&l=SCI|3区&or=false
# 其中dn表示 打开的数据库编号(从1开始)-论文的编号#,..
# l表示检索的Label, 不同词使用竖线|分割, or如果是true则表示不同词是或的关系进行检索, 默认为false是且的关系
# url不要自己encode编码, dn如果有值则会忽略l参数

on path2url(thepath)
	tell current application's NSString to set urlString to stringWithString_(thepath)
	set theDecodedURL to urlString's stringByRemovingPercentEncoding -- 4 is NSUTF8StringEncoding
	return theDecodedURL as Unicode text
end path2url

set fullURL to path2url("$0")

on theSplit(theString, theDelimiter)
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theArray to every text item of theString
	set AppleScript's text item delimiters to oldDelimiters
	return theArray
end theSplit

on intersection(list_list) # 多个list求交集
	local newList, listB, a
	set newList to item 1 of list_list
	repeat with listA in list_list
		set listB to {}
		repeat with a in listA
			set a to contents of a -- dereference implicit loop reference
			if {a} is in newList then set end of listB to a
		end repeat
		set newList to listB
	end repeat
	return newList
end intersection

on union(list_list) # 多个list求并集, 一个list内部重复的元素会去除
	local listA, listB
	set listA to {}
	repeat with listB in list_list
		set listA to listA & listB
	end repeat
	set listB to {}
	repeat with a in listA
		set a to contents of a -- dereference implicit loop reference
		if {a} is not in listB then set end of listB to a
	end repeat
	return listB
end union

set l_or to "false"
if (count of text items of fullURL) is greater than 1 then
	set fragment to item 2 of theSplit(fullURL, "?")
	set AppleScript's text item delimiters to "&"
	set kvs to text items of fragment
	repeat with kv in kvs
		set AppleScript's text item delimiters to "="
		set k to text item 1 of kv
		set v to text item 2 of kv
		if k = "dn" then
			set database_recNum to v
		end if
		if k = "l" then
			set Label to theSplit(v, "|")
		end if
		if k = "or" then
			set l_or to v
		end if
	end repeat
end if

if database_recNum ≠ "" then
	set myResults to {}
	repeat with dr in theSplit(database_recNum, ",")
		set database to item 1 of theSplit(dr, "-")
		set recNum to item 2 of theSplit(dr, "-")
		set end of myResults to "<RecordID database=\"" & database & "\" recNum=\"" & recNum & "\" />"
	end repeat
else
	tell application "EndNote 20"
		set myResults to {}
		repeat with l in Label
			set end of myResults to find l in field "Label"
		end repeat
	end tell
	if l_or = "true" then
		set myResults to union(myResults)
	else
		set myResults to intersection(myResults)
	end if
end if

tell application "EndNote 20"
	activate
	show records in myResults in first window
end tell
1 Like

Thanks again, @tsc.

@tsc and/or other Endnote users: Does the modified version work for you?