Creating Text Notes From Safari Script
Creating Text Notes From Safari Script
- Subject: Creating Text Notes From Safari Script
- From: "Johnny AppleScript" <email@hidden>
- Date: Sun, 12 Jan 2003 07:10:01 -0700
Hey All,
Just thought we'd contribute a script we slapped together to quell
frustration with Safari's inability to drag-n-drop selected text to a Text
Clipping, and also the ability to convert an entire page to plain text.
We're also looking for, or need to write a script that will emulate MSIE 5's
'Scrapbook' feature; we need to be able to save complete, working pages,
including user-entered form content. If anyone knows of some base work we
can chew on, please let us know.
=============paste begin===========================
-- 'Create Desktop Text Note From Selected Safari Text' Script
(* Safari doesn't appear to support an AppleScript command to Copy selected
text to the Clipboard, so this script relies on the user selecting only the
desired text, or using 'Select All' (Command-A), and then using 'Copy'
(Command-C) before executing this script.
Ideally, the user would use Keyboard Maestro, FruitMenu or Youpi Key (free)
to tell Safari to 'Copy' the selection and then execute this script.*)
global theDate
global theName
(*Remember, you must first make your desired text selection in Safari...*)
get the clipboard
set theClipboard to the clipboard as text
(* See how big the file will be for naming purposes...*)
try
if the number of characters of theClipboard is less than 31 then
set theLimit to the number of characters
else if the number of characters of theClipboard is greater than 31 then
set theLimit to 31
end if
(* Large selections results in a 'stack overflow' error; simple error
handler here...*)
on error
set theLimit to 31
end try
(* Use this information to generate a file name...*)
set textString to characters 1 thru theLimit of theClipboard as string
(* Make sure the file name doesn't have any illegal characters... *)
set the textString to replaceCharsName(textString, "/", "-")
set the textString to replaceCharsName(textString, ":", ".")
on replaceCharsName(thisText, searchString, replacementString)
set AppleScript's text item delimiters to the searchString
set the itemList to every text item of thisText
set AppleScript's text item delimiters to the replacementString
set thisText to the itemList as string
set AppleScript's text item delimiters to ""
set theName to thisText as text
end replaceCharsName
(* To make sure the filename is unique, so it doesn't generate an error or
write appended information to an existing note, we're going to date-stamp
the file name... *)
set the dateString to ((the current date) as string)
(* Again, we look for illegal characters...*)
set the dateString to replaceChars(dateString, ",", "")
set the dateString to replaceChars(dateString, ":", ".")
on replaceChars(thisText, searchString, replacementString)
set AppleScript's text item delimiters to the searchString
set the itemList to every text item of thisText
set AppleScript's text item delimiters to the replacementString
set thisText to the itemList as string
set AppleScript's text item delimiters to ""
set theDate to thisText as text
end replaceChars
(*Now we take the file naming perameters to Safari... *)
tell application "Safari"
(* Gather some more information to stamp the note internally...*)
set theWindowName to the name of the front window
set theURL to the URL of the front document
(* Name the file here; yes, I know, ugly use of file name limits and
formatting; the point was to create file names that gave hints to the
content; the unique date was required to prevent duplication and
overwrites...*)
set theFile to theName & "... " & theDate
(* Set the filepath to the Desktop of the current user; some people may
wish to modify this path to a specific folder; e.g., "Web Clippings"; alter
as desired. *)
set pathstring to ((path to desktop) as text) & theFile
(*Generate the final content and write the note...*)
set writeString to "Source: " & theURL & return & "Page Title: " &
theWindowName & return & "Date: " & (current date) & return & return & (the
clipboard)
set theNote to open for access file pathstring with write permission
write writeString to theNote
close access theNote
end tell
==============paste end=========================
Testing has been limited; Comments and suggestions most welcome.
Cheers
JA
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.