Tinderbox Forum

Stamp or AS to Copy $Name and $Text of selected notes to the Clipboard?

Is it possible to create a stamp to copy to the clipboard the name and text of selected notes?

Nothing fancy, just the $Name\n$Text\n\n of each selected note?


The problem is that stamps act on each note individually. So, there’s no way for a stamp to iterate over each of the selected notes.

Why do you want to do this? And why a stamp?

1 Like

Not sure whether that’s helpful but to copy the name and text of a single note:

runCommand("export LANG='en_US.UTF-8' && pbcopy",

Thanks Pete and MarkB.

Sorry for making my question not clearer and easier to answer.

Yes, my need, is to automate the copy to the clipboard process for many selected notes in groupings at a time, unfortunately not a single note. I initially thought a stamp “might” / “hoping” it would work since I do not know AppleScript.

My use case is very specific. I have my tinderbox medical knowledgebase that I am studying. I am transferring many selected note groupings from tinderbox to another medical database. I am curating the notes I select to transfer. I do not want to transfer en masse. As I read and study, I select the curated notes I want. I do not want to break my flow.

In my case, I will not import into a spreadsheet or need any delimiter format. I just need $Name \r $Text |n|n. that is it.

In Pseudocode:

I think it translates to something like this:

I found some older code Sumner had posted a while back to get me most of the way there. Here is the link to the original thread:

NB, it works perfectly for me but in case anyone wants to use the code, just make sure all curly quotes get changed to straight works. I would recommend using the link to the original code because I have noticed, in the past, when I paste code, it somehow gets changed to curly quotes in the post. Sorry, I have not figured it out yet.

Anyway, for my use case, the only part, left, I need to figure out (and working on now) is how to:

  1. Remove the top header row (which I do not need)
  2. Remove the " " beginning and ending each “$Name” “$Text” which I do not need.


set grabAttribs to {“Name”, “Text”}
set myDelimiter to " "
set text item delimiters to quote & myDelimiter & quote

copy grabAttribs to attribVals
set numCols to grabAttribs’s length
tell application “Tinderbox 9”
tell front document’s selections – (note use of plural)
repeat with i from 1 to numCols
set attrName to grabAttribs’s item i
set attribVals’s item i to attribute attrName’s value

end repeat
end tell
end tell
set numRows to attribVals’s item 1’s length
set outStr to quote & (grabAttribs as string ) & quote & return # header row
repeat with i from 1 to numRows
set rowItems to {}
repeat with j from 1 to numCols
set rowItems’s end to attribVals’s item j’s item i
end repeat
set outStr to outStr & quote & (rowItems as string ) & quote & return # body row
end repeat
set the clipboard to outStr
–return outStr – uncomment this line to view output in Script Editor ‘Result’ pane

1 Like
  • Save the AppleScript.
-- Copy selected notes' name and text 

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

tell application id "Cere"
		if not (exists front document) then error "Please open a Tinderbox"
		tell front document
			set theNotes to selections
			if theNotes = {} then error "Please select some notes"
			set theList to {}
			repeat with thisNote in theNotes
				set thisNote_Text to text of thisNote
				set thisNote_Text_trimmed to my trimWhitespaceAtStartAndEnd(thisNote_Text)
				set end of theList to (name of thisNote) & linefeed & (thisNote_Text_trimmed) & linefeed & linefeed
			end repeat
			set theText to my tid(theList, linefeed)
			set the clipboard to theText
		end tell
	on error error_message number error_number
		if the error_number is not -128 then
			display alert "Tinderbox" message error_message as warning
		end if
	end try
end tell

on trimWhitespaceAtStartAndEnd(theText)
		set theString to (current application's NSString's stringWithString:theText)
		set theString to theString's stringByTrimmingCharactersInSet:(current application's NSCharacterSet's newlineCharacterSet())
		return theString as string
	on error error_message number error_number
		if the error_number is not -128 then display alert "Error: Handler \"trimWhitespaceAtStartAndEnd\"" message error_message as warning
		error number -128
	end try
end trimWhitespaceAtStartAndEnd

on tid(theInput, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	if class of theInput = text then
		set theOutput to text items of theInput
	else if class of theInput = list then
		set theOutput to theInput as text
	end if
	set AppleScript's text item delimiters to d
	return theOutput
end tid

  • Create a stamp and replace the example path with the AppleScript’s path on your mac
runCommand("osascript '/path/to/the/script'")
1 Like

Wow…this is perfect. Many thanks Pete!

1 Like