I made some changes an existing script (“Cookie” by John Rethorst) in order to have a signature, consisting of a fixed part (i.e. my name and so on) and a part randomly chosen from a fortune file (i.e. an astonishingly witty quotation), copied to the clipboard. It’s below (the paths are to be filled in, of course).
Now I want the script to also paste the clipboard contents into the running application. That is: when I click “Okay” in the dialog box, I want the signature to be copied to the clipboard and pasted into my frontmost window.
I’ve searched and found lines like “tell application “System Events” to keystroke “v” using command down”, but I’ve inserted this toward the end of the script, and it doesn’t work. (Instead, the text is merely copied to the keyboard – it’s like I never added anything.) I am using Tiger.
Can anyone help?
Thanks!
- Phil
on run
try
try
with timeout of 2 seconds
set myCookie to (do shell script "/opt/local/bin/fortune "[path-to-my-fortune-file]") -- this is the random part of the sig
set myFixed to (do shell script "more [path-to-textfile-with-fixed-text]") -- this is the fixed part of the sig
end timeout
on error myErr -- error catcher with a dialog
display dialog myErr buttons {"Again", "Cancel"} default button 2 giving up after 10
set theButton to (button returned of the result) -- the button returned from the dialog
if theButton = "Again" then run -- runs the script again!
end try
-- user control of the cookie through a dialog
display dialog myCookie buttons {"Cancel", "New", "Keep"} default button 3 cancel button 1 -- show dialog
set theButton to (button returned of the result) -- the button returned from the dialog
if theButton = "New" then run -- runs the script again
set the clipboard to (myFixed & "
" & myCookie) -- concaenates the fixed text, a line-break, and the random selecton; and sends the result to the clipboard
end try
end run