2.5 KiB
2.5 KiB
Plak URL scheme
Plak is the user's scratchpad app for macOS. Other apps add text to it through two plak:// URLs. This page is the contract that Helder relies on.
plak://append?text=<text>
Adds the text at the end of the Plak page, as a new block with its own created date.
- Percent-encode the text as a URL query value: space
%20, newline%0A,&%26,+%2B,#%23. - Never encode a space as
+. Plak keeps a+literal, so the block would show+signs. - Plak detects the content type as for a paste. PHP, JSON, XML and CSV become a code block or a table. All other text becomes plain text.
plak://paste
Adds the current contents of the macOS general pasteboard, text or images.
- Use it for images and for text over about 100 KB, where a long URL can fail to open.
- Put the content on the pasteboard first, then open the URL.
- Save the user's clipboard before, and restore it one second after.
What Plak does
- Plak starts if it is not running. It shows its window, scrolled to the new content, and takes the focus.
- An empty or missing
textadds nothing, but Plak still shows. - Every other
plak://URL does nothing. - There is no callback and no error result. The sender cannot know if the add worked.
Opening the URL
open "plak://append?text=Hello%20from%20my%20app"
var components = URLComponents()
components.scheme = "plak"
components.host = "append"
components.queryItems = [URLQueryItem(name: "text", value: text)]
// URLQueryItem leaves "+" as it is; encode it yourself.
components.percentEncodedQuery = components.percentEncodedQuery?
.replacingOccurrences(of: "+", with: "%2B")
if let url = components.url { NSWorkspace.shared.open(url) }
open location "plak://append?text=Hello%20from%20my%20app"
shell.openExternal("plak://append?text=" + encodeURIComponent(text))
subprocess.run(["open", "plak://append?text=" + urllib.parse.quote(text, safe="")])
In Helder
- The Plak item in the right-click menu of the code and of both terminal panes uses this scheme. See behaviour.md and the right-click guide.
- URL building and the 100 KB choice:
PlakinSources/HelderCore/Files/Plak.swift. The limit counts UTF-8 bytes. - Opening the URL and the clipboard save and restore:
SystemActing.sendToPlakinSources/HelderUI/Shell/SystemActions.swift.
Plak replaces Helder's old project note (.notes.txt, Cmd+N), which is gone.