Copying a text selection from Safari to Tinderbox


I’m new to Applescript. I am trying to create a script that takes a highlighted text selection in Safari, appends the URL and Title and pastes it into a new Tinderbox note. I have taken code from other scripts, but I am having trouble getting them to work.

The script below attempts to get the highlighted section of text in the Safari window, the URL, and the URL’s title and store them in the clipboard. I would like the script to then append these variables together and put this piece of text in the clipboard. The script would then paste the clipboard into Tinderbox as a new note.

Right now, I’m just trying to paste the contents of current_url into a new note, but it does not work.

I copied the Safari code from appSafariToiGTD.applescript in the iGTD application.
The rest I cobbled from webpages and sample code.

tell application "Safari"
	set current_documents to documents
	set current_document to item 1 of current_documents
	set current_url to URL of current_document
	set result to URL of current_document
	set current_content to my get_safari_selection()
	set current_title to my get_safari_title()
end tell

tell application "Tinderbox"
	set current_url to the clipboard as string
	tell application "System Events"
		keystroke "v" using {command down}
	end tell
end tell

on get_safari_selection()
	set getSelection to "
var theSel = '';
if (getSelection) {
    theSel = getSelection();
} else if (document.getSelection) {
    theSel = document.getSelection();
} else if (document.selection) {
    theSel = document.selection.createRange().text;
} else if (window.getSelection) {
    theSel = window.getSelection();
'' + theSel;
	tell application "Safari" to return (do JavaScript getSelection in document 1) as Unicode text
end get_safari_selection

on get_safari_title()
	set getTitle to "
var theTitle = '';
theTitle = document.title;
'' + theTitle;
	tell application "Safari" to return (do JavaScript getTitle in document 1) as Unicode text
end get_safari_title

My questions are:

  1. Does the Safari section of the script get the
  • Text Selection
  • URL
  • URL Title
  1. How can I see the value of these variables? Could they get output to the “Result” window?

  2. What is the syntax to say

Thank you in advance for your help,


Model: MacBook Pro
AppleScript: 1.10.7
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)

Hi Lance,

try just this, it copies the values you want to the clipboard with your requested syntax

property LF : ASCII character 10
tell application "Safari"
	set {theDoc, theURL} to {name, URL} of document 1
	set selectedText to (do JavaScript "\"\"+window.getSelection();" in front document)
end tell
set the clipboard to selectedText & LF & LF & theDoc & LF & theURL

Thank you for your lightning fast response. Your code copies the Safari information to the clipboard as advertised. However, my code for pasting it into Tinderbox doesn’t work. I’ll work on it tonight on my own.