Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MyShout

macrumors newbie
Original poster
Sep 19, 2014
3
0
Hi,
I have a small script that I want to use to copy a png file into the clipboard.
Which I want to go like this.

Code:
set pngData to read file "copytoclipboard.png" as «class PNGf»
set the clipboard to pngData

In this case I want to put the compiled script in the same directory where the png file is, hoping that it would be able to find the file. Unfortunately that is not the case.

If I give the thing a hard name like in the next example it will work.
Code:
set pngData to read file "Users:myshout:Library:myapplication:copytoclipboard.png" as «class PNGf»
set the clipboard to pngData

But this is not what I want as I want to be able to distribute the script in my application, so putting the compiled script next to the png file is the most secure way to distribute.

Anyone knows how the apple script can figure out the file name from the directory from which it is executed ??

Thank in advance,

@+Maarten,
 
Last edited by a moderator:
This did it

The following worked:

Code:
set aHome to ":Users"
set aUser to system attribute "USER"
set aFileName to "Library:StakePoint:stakepointclipboard.png"
set totalName to aHome & ":" & aUser & ":" & aFileName
set pngData to read file totalName as «class PNGf»
set the clipboard to pngData

Not sure if there are many macs around who rename there Users directory name, but asking for the system attribute "HOME" gives "/Users/" which gives me the problem to replace the "/" by ":"

Thank you for the help.

Regards

@+Maarten
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.