Hi guys, this is my first time playing with AppleScript and I must admit - daamn its sweet
Anyway, I need a little help on how to paste some static text and a dynamic filename into the content of my clipboard.
How do I paste something into my clipboard so i can paste it by pression opt+v?
How do I get the filename om a file, selected at my desktop?
How do I add some static text (like www.myweb.com/img/) before the filename, in the clipboard memory?
For your info, the script goes like this: Take screenshot > place screenshot to desktop > name file with date & time > move file to a folder called âuploaded2ftpâ > upload to a ftp > place som text and the complete filename in my clipboard so i by pressing opt+v get http://www.myweb.com/img/<filename.ext>
You can copy text to the clipboard with something like this:
set some_text to "some text"
set file_name to "filename.pdf"
set the clipboard to some_text & return & file_name
You donât need to get the file name or select a file because you already have it. Something like this assuming there is a folder named âuploaded2ftpâ in the current userâs folder:
set file_name to (do shell script "date '+%m:%d:%y_%H-%M-%S'")
set file_extension to ".pdf"
set folder_path to POSIX path of ((path to "cusr" as string) & "uploaded2ftp:")
set file_path to quoted form of (folder_path & file_name & file_extension)
-- take snapshot
do shell script "screencapture " & file_path
Edited: BTW, I am running Jaguar, so the snapshot taken with âscreencaptureâ might not be a pdf on your computer. Also, there are different ways to get the date and time using AppleScript instead of unix âdateâ command, but I donât have the short date parameter here in Jaguar, so I used the unix.
As I said, you donât to select your file because you already have the name in your script.
With a little adjustments, this is what I came up with:
set current_date to (do shell script âdate â+%m:%d:%y_%H-%M-%Sââ)
set file_extension to â.pdfâ
set file_name to (âscreenshot_1_â & current_date & file_extension)
set folder_path to POSIX path of ((path to desktop as string) & âuploaded2ftp:â)
set file_path to quoted form of (folder_path & file_name)
â take snapshot
do shell script "screencapture " & file_path
â set clipboard text
set clip_text to âwww.myweb.com/img/â & file_name
set the clipboard to clip_text
You should change the extension to png. I moved my folder âuploaded2ftpâ to the desktop and changed the âpath toâ command to the desktop. Also, your web page address was added.
Note when pasting clipboard text, the application youâre pasting to needs to be frontmost, but I suspect the you donât really need to use the clipboard here.
Oops, I forgot to put the script in the AppleScript tags. Safari might have problems copying the text.
set current_date to (do shell script "date '+%m:%d:%y_%H-%M-%S'")
set file_extension to ".pdf"
set file_name to ("screenshot_1_" & current_date & file_extension)
set folder_path to POSIX path of ((path to desktop as string) & "uploaded2ftp:")
set file_path to quoted form of (folder_path & file_name)
-- take snapshot
do shell script "screencapture " & file_path
-- set clipboard text
set clip_text to "[url=http://www.myweb.com/img/]www.myweb.com/img/[/url]" & file_name
set the clipboard to clip_text