用applescript写了一个脚本,希望有大佬帮我优化一下,可以付费

没有编程基础,所以遇到一些自己暂时不能解决的障碍。

具体地,我现在用applescript只能获取最近编辑的笔记的id,不知道有什么办法可以获取目前Marginnote中选中的笔记卡片的id?咨询了大佬,marginnote里选中笔记的时候会返回NSnotification,里面应该有笔记的信息。目前的问题就是,不知道applescript怎么调用。

目前的写的东西是这样的:

tell application "System Events"
	tell application "MarginNote 3" to activate
	set frontApp to name of first application process whose frontmost is true
end tell

tell application frontApp
	if the (count of windows) is not 0 then
		set window_name to name of front window
	end if
end tell

on findAndReplaceInText(theText, theSearchString, theReplacementString)
	set AppleScript's text item delimiters to theSearchString
	set theTextItems to every _text item_ of theText
	set AppleScript's text item delimiters to theReplacementString
	set theText to theTextItems as _string_
	set AppleScript's text item delimiters to ""
	return theText
end findAndReplaceInText

set window_name to findAndReplaceInText(window_name, "MarginNote 3 - ", "")

tell application "MarginNote 3"
	set nbk to item 1 of (search notebook window_name)
	set nLst to note ids of nbk
	set nLst to item 1 of nLst
	# 获取所有笔记id中的第一项,也就是最近修改项
set nLst to fetch dictionaries nLst
# 获取最近修改项的dictionaries

有没有办法通过applescript直接获取当前选中的笔记卡片的信息啊 :yum: :yum:

Hello

想获取选中的笔记卡片做什么呢?

如果是替换文本,其实插件会更适合做这个。

Kind Regards,
MarginNote-Edward
Support Team

其实是一个简单的脚本,把卡片的内容和划重点的地方导入到间隔重复软件(supermemo)里制卡,目前已经基本实现了,有一个小缺点就是如果最后编辑的是comment,那么只能获取那个comment的内容,没有comment dictionaries,不是整张卡片的内容;只有在最后编辑excerpt text的时候,上面的代码才会返回整个卡片的信息,包括卡片里的comment dictionaries。
说一下我的使用习惯,如果我希望某些内容在同一张卡片里,我是先摘录出某一节里的一段内容,后面的我都用“合并”,形成同一张卡片。
就在写这段话的时候,我想到的是模拟按键tab然后enter,这样item 1就是整张卡片 :rofl: :rofl: