(You need to install Satimage plugin for applescript to run this script)
Why does this script not work in TextEdit?¨
Secondly, why does it sometimes(always, in case of Firefox) throw a beep though it creates the clipping properly and also shows the Growl notification?
Lastly, it does not work properly if the selected text is less than 31 characters (which must be a result of my poor scripting knowledge)
tell application "System Events"
delay 0.3
keystroke "c" using command down
end tell
--get the clipboard
delay 0.2
set theClipboard to the clipboard as text
try
if the number of characters of theClipboard is less than 32 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
on error
set theLimit to 31
end try
set textString to characters 1 thru theLimit of theClipboard as string
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
property dragdata : «data drag01000000000000000000000000000700747874750000000100000000000000006C797473000000010000000000000000545845540000000100000000000000003866747500000001000000000000000020465452000000010000000000000000363174750000000100000000000000006C747375000000010000000000000000»
tell application "Finder" to set F to (make new clipping at desktop to the textString) as string
put resource (the clipboard as Unicode text) to file F type "utxt" index 256
try
put resource (the clipboard as «class RTF ») to file F type "RTF " index 256
end try
put resource dragdata to file F type "drag" index 128
tell application "GrowlHelperApp"
set the allNotificationsList to {"Clipping Notifier"}
set the enabledNotificationsList to {"Clipping Notifier"}
register as application "Clipping Notifier" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Finder"
notify with name "Clipping Notifier" title "Clipping Notifier" description textString application name "Clipping Notifier"
end tell