# New Scripts for MarginNote4

**URL:** <https://discourse.hookproductivity.com/t/new-scripts-for-marginnote4/7843>\
**Category:** Showcases and Use Cases\
**Created:** [May 16, 2024, 6:08pm UTC](https://discourse.hookproductivity.com/t/new-scripts-for-marginnote4/7843 "2024-05-16T18:08:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AW2307](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@AW2307](https://discourse.hookproductivity.com/u/AW2307)\
**Post date:** [May 16, 2024, 6:08pm UTC](https://discourse.hookproductivity.com/t/new-scripts-for-marginnote4/7843/1 "2024-05-16T18:08:19Z")

</div>

Hi,

MarginNote has finally brought out a long-awaited new major version and released MarginNote 4. It’s great!

Since the old Hookmark scripts no longer worked, I’ve created a very simple replacement based on UI scripting. It seems to work without issues in my testing.

**Get Name**

```auto
try
    tell application "System Events" to tell process "MarginNote 4"
        delay 0.1

        click menu item "Copy Card Clone" of menu "Card" of menu bar 1
        delay 0.1
        set clipboardContent to the clipboard
    end tell
    
    -- Retain only the content up to the first line break
    set theURL to paragraph 1 of clipboardContent

    return theURL

on error msg
    display dialog msg
end try

```

**Get Address**

```auto
try
    tell application "System Events" to tell process "MarginNote 4"
        delay 0.1

        click menu item "Copy Card URL" of menu "Card" of menu bar 1
        delay 0.1
        set clipboardContent to the clipboard
    end tell

set theTitle to the clipboard

    return theTitle

on error msg
    display dialog msg
end try

```

---

<div class="post-metadata">

**Author:** ![AW2307](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@AW2307](https://discourse.hookproductivity.com/u/AW2307)\
**Post date:** [May 26, 2024, 9:47am UTC](https://discourse.hookproductivity.com/t/new-scripts-for-marginnote4/7843/2 "2024-05-26T09:47:05Z")

</div>

Note that I’ve now modified the “Get Name” script in the original post to include only the title of the card when creating a Hook.

---

<div class="post-metadata">

**Author:** ![bchend](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/b/dbc845/32.png) [@bchend](https://discourse.hookproductivity.com/u/bchend)\
**Post date:** [May 27, 2024, 12:50am UTC](https://discourse.hookproductivity.com/t/new-scripts-for-marginnote4/7843/3 "2024-05-27T00:50:59Z")

</div>

Thank you very much for your scripts, @AW2307 .

The script server has been updated. The version is 327.

Please let us know if there is any problem.

Thank you

---

<div class="post-metadata">

**Author:** ![Elise](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@Elise](https://discourse.hookproductivity.com/u/Elise)\
**Post date:** [November 7, 2024, 2:08pm UTC](https://discourse.hookproductivity.com/t/new-scripts-for-marginnote4/7843/4 "2024-11-07T14:08:48Z")

</div>

Could Hookmark please be compatible to Marginnote 4?

---

<div class="post-metadata">

**Author:** ![bchend](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/b/dbc845/32.png) [@bchend](https://discourse.hookproductivity.com/u/bchend)\
**Post date:** [November 7, 2024, 6:40pm UTC](https://discourse.hookproductivity.com/t/new-scripts-for-marginnote4/7843/5 "2024-11-07T18:40:09Z")

</div>

Thank you for getting in touch, @Elise .

Hookmark is supposed to work with cards of Marginnote 4, since script version 327.

What’s your system language?

---

<div class="post-metadata">

**Author:** ![Huang](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@Huang](https://discourse.hookproductivity.com/u/Huang)\
**Post date:** [August 5, 2025, 3:32am UTC](https://discourse.hookproductivity.com/t/new-scripts-for-marginnote4/7843/6 "2025-08-05T03:32:49Z")

</div>

I’ve decoded MarginNote’s **UI status URL** and would like to share a solution for getting the current document link in a study set.

## Get Name

```auto
tell application "System Events"
	tell process "MarginNote 4"
		set the clipboard to ""
		
		-- Check if an item is selected by seeing if "Copy" is enabled
		if enabled of menu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1 then
			-- An item is selected, so copy it
			click menu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1
			delay 0.1
			set theTitle to ""
			
			-- Wait for the clipboard to be populated
			repeat 3 times
				set theItem to the clipboard
				delay 0.1
				try
					set theTitle to item 1 of paragraphs of theItem
				end try
				if theTitle is not null and the length of theTitle is not 0 then
					exit repeat
				else
					delay 0.2
				end if
			end repeat
			return theTitle
		else
			-- No item is selected, get the window name from the "Window" menu
			try
				tell application "System Events"
					set frontApp to name of first application process whose frontmost is true
					if frontApp is "MarginNote 4" then
						tell application process "MarginNote 4"
							set theWin to front window
							set theName to name of theWin
							return theName
						end tell
					else
						return "MarginNote 4 is not in the foreground."
					end if
				end tell
			on error errMsg
				return "Error：" & errMsg
			end try
			
		end if
	end tell
end tell

```

## Get Address

```auto

tell application "System Events"
	tell process "MarginNote 4"
		set the clipboard to ""
		
		if enabled of menu item "Copy Card URL" of menu 1 of menu bar item "Card" of menu bar 1 then
			click menu item "Copy Card URL" of menu 1 of menu bar item "Card" of menu bar 1
			delay 0.1
			
			
			set theURL to ""
			repeat 3 times
				set theURL to the clipboard
				if theURL is not null and the length of theURL is not 0 then
					exit repeat
				else
					delay 0.1
				end if
			end repeat
			
			return theURL
		else
			
			try
				click menu item "UI Status URL" of menu 1 of menu bar item "StudySet" of menu bar 1
				delay 0.1
				
				set theURL to ""
				repeat 3 times
					set theURL to the clipboard
					if theURL is not null and the length of theURL is not 0 then
						exit repeat
					else
						delay 0.1
					end if
				end repeat
				
				set pythonScript to "decode_mnurl.py" -- remember to replace the path 
				set topicId to do shell script "python3 " & quoted form of pythonScript & " " & quoted form of theURL
				
				return topicId
			on error
				
				return "Cannot get UI Status URL"
			end try
		end if
		
	end tell
end tell

```

⚠ You’ll need a Python environment, and you’ll have to replace the Python file [decode\_mnurl.py](https://drive.google.com/file/d/1KjzA60xICfFSC_rTn4fBhomXRFTDF7pL/view?usp=sharing) address in the “Get address”.
