Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Feature Complete version: from selection, not pasteboard' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Feature Complete version: from selection, not pasteboard
Authored by: klktrk on Dec 13, '03 05:59:16PM
With help from the macscripters bbs, snippets from this hint page, and Nicholas Riley's LispMe importer (which showed me how to deal with setting categories), I've made the following script which grabs selected text from ANY frontmost app allows you to edit the title field, select a primary category and either just file it away in Palm Desktop, or open it in Palm Desktop for editing.

Enjoy!!!

Open this script in a new Script Editor window.

tell application (path to frontmost application as string)
activate
tell application "System Events"
set GUIenabled to get UI elements enabled
if GUIenabled = false then
display dialog "This script requires you to enable access for assistive devices in the Universal Access preference pane. You have not done so." buttons {"OK"} default button 1 with icon 0 giving up after 5
return
end if
set theProcess to item 1 of (every process whose frontmost is true)
set oldClipboard to the clipboard
try
tell theProcess to keystroke "c" using command down
delay 1 --give it time to update
set selectedText to (the clipboard) as string
set the clipboard to oldClipboard
on error msg
set selectedText to missing value
set the clipboard to oldClipboard
display dialog msg with icon 0
end try
end tell
if selectedText = missing value then
display dialog "Either the AppleScript GUI syntax does not work for this app, or the selection could not be converted to the appropriate format" buttons {"OK"} default button 1 with icon 0 giving up after 5
else if selectedText = "" then
display dialog "You need to select some text to put in the memo!" buttons {"OK"} default button 1 with icon 0 giving up after 5
else
if (count of selectedText) is greater than 20 then
set memoTitle to text 1 thru 20 of selectedText
else
set memoTitle to selectedText
end if
display dialog "Enter a title for your memo (20 chars max): " default answer memoTitle default button "OK"
set memoTitle to text returned of result
set memoTitle to «class ktxt» of (result as record)
if (count of memoTitle) is greater than 20 then
set memoTitle to text 1 thru 20 of memoTitle
end if

tell application "Palm Desktop"
set memoCategories to {}
repeat with thisCategory in categories
set memoCategories to memoCategories & {(name of thisCategory)}
end repeat
end tell

set categoryChosen to choose from list memoCategories with prompt "Select a category for this memo."
if categoryChosen is not false then
set memoCategory to item 1 of categoryChosen
else
set memoCategory to ""
end if


set contentsTextPreview to "This is your new memo:

Title: " & memoTitle & "
Category: " & memoCategory & "
Body: " & selectedText
if (count of contentsTextPreview) > 340 then
set contentsTextPreview to ((text 1 thru 300 of contentsTextPreview) & "…")
end if

display dialog the contentsTextPreview buttons {"Cancel", "Edit in Palm Desktop", "File in Palm Desktop"} default button 3 with icon 1

set userChoice to the button returned of the result
if userChoice is not "Cancel" then
tell application "Palm Desktop"
try
set newMemo to make new memo with properties ¬
{title:(memoTitle), contents:(selectedText), primary category:(category memoCategory)}
on error msg
display dialog msg
end try
if userChoice is "Edit in Palm Desktop" then
activate
show newMemo
end if
end tell
end if
end if
end tell

[ # ]