Hello,
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"
activate
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:
- Does the Safari section of the script get the
- Text Selection
- URL
- URL Title
-
How can I see the value of these variables? Could they get output to the “Result” window?
-
What is the syntax to say
Thank you in advance for your help,
Lance
Model: MacBook Pro
AppleScript: 1.10.7
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)