As Partron22 as indicated, you need to set the path to your image file more
clearly, I have written a test script for you, but I have made it to work on
an image file called "Play Button.png" on my system, located in my Documents
folder, so you will have to point to an image file on your own system.
Code:
set picFile to (path to documents folder) & "Play Button.png" as text
try
set picFile to picFile as alias
on error errMessage number errNumber
display alert errMessage & space & "error number " & errNumber message ¬
"Cant find file " & picFile & ", check file exists and the supplied path." as informational
return
end try
tell application "Finder"
try
open document file picFile
on error errMessage number errNumber
display alert errMessage & space & "error number " & errNumber message ¬
"Finder was unablke to open the file " & picFile as informational
return
end try
end tell
delay 0.5
tell application "System Events"
set runningApps to name of every application process whose visible is equal to true
if runningApps contains "Preview" then
keystroke "a" using command down
delay 0.5
keystroke "c" using command down
delay 0.5
tell application "Preview" to quit
return
else
display alert ¬
"Could not select all, and copy to the clipboard the file" & picFile & return & ¬
" because the application Preview is not active." as informational giving up after 30
return
end if
end tell
The First line of code sets the path to my image file as text, then the third line
changes the text into an alias type, which the Finder and System Events will
recorgnize as a file type.
You will notice that I have included some error checking into the script, this
is an important part of scripting and programming, as you dont want your
system to crash or display alert messages, when your file cant be found, or
the applications your sending commands too, does not understand these
commands.
Also I have put delays into the code, this is also important, as you need to
allow the Finder and Preview applications, time to react to your commands,
because if you send the commands to quickly, then the apps dont have time
to react, and you will get system error messages.
If you post the exact path to your image file, then I will show you how to
set a path to it, also you might consider using an open file dialog box, so that
you could choose any image file on youe computer, instead of hard coding the
path to only one image file.
Hope this helps you.
Regards Mark