Pasting text & filename to clipboard?

Hi guys, this is my first time playing with AppleScript and I must admit - daamn its sweet :cool:

Anyway, I need a little help on how to paste some static text and a dynamic filename into the content of my clipboard.

  1. How do I paste something into my clipboard so i can paste it by pression opt+v?
  2. How do I get the filename om a file, selected at my desktop?
  3. 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>

Thanks!

Hi Ken,

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.

gl,

Aah, thats great! Im almost there now :slight_smile:

Just one more thing - the filename. Is there a trick to get the filename?

This is one way:

tell application "Finder" to set the clipboard to name of (info for (selection as alias))

Using this, i get a error: Cant make {} into type alias . (-1700)

If I instead use this;

tell application "Finder" to set the clipboard to name of selection

My output says {alias “Macintosh HD:Users:kennethjensen:Desktop:uploaded2ftp:screenshot_1_03-05-2006_20-23-06.png”}

But I only need the filename - in this case “screenshot_1_03-05-2006_20-23-06.png”.

Any ideas?

Hi Ken,

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.

gl,

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