Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Find image path mac

Participant ,
Jul 08, 2019 Jul 08, 2019

Hey Guys,

I’ve been trying to use this line of code to find out what the specific path image is on mac.

I’ve not having any luck (an error on my part i'm sure) and would love someone to give me an example of how it should look.

So far I have this…

alert(File.decode(File.openDialog()));


and this is what I have but it is not returning the path string.

alert(File.decode(File.openDialog(~/Users/liam/Desktop/thumb.png)));

Thanks for your time.

Liam

TOPICS
Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jul 08, 2019 Jul 08, 2019

I just gave it a quick test - your snippet is somewhat buggy - on line 1 you are specifying the path to the image file, but on line 2 you are appending file name. And therefore ESTK cannot find such file - it does not exist.

To be safe, you should check if the file exists before reading it. So if you added this on line 3, you'd get a message saying that such file does not exist

if (!f.exists) {

    return alert('File ' + f.fsName + ' does not exist');

}

That's why the result was just (new String(""))

...
Translate
Advocate ,
Jul 08, 2019 Jul 08, 2019

I'm not entirely sure what you are trying to achieve here, but here's a bare minimum of how to use File.openDialog() method.

P.S. If you're interested, I'd suggest you read more about File object in the docs http://estk.aenhancers.com/3%20-%20File%20System%20Access/file-object.html?highlight=opendialog

var myFile = File.openDialog('Select some file');

if (!myFile) {

    // user clicked cancel

} else {

    var pathToFile = myFile.fsName;

    alert(pathToFile);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 08, 2019 Jul 08, 2019

Hi Tomas,

Thanks for your reply.

Interesting link and perhaps I'm a little off in what I would like to achieve.

A little background info. I am following a tutorial to turn an image into a binary file. I am using this code below.

var path = '/Users/liam/Desktop/Thumb.pngg';

var f = File(path+"Thumb.png");

f.encoding = 'BINARY'

f.open('e');

var binary;

binary = f.read().toSource();

var myFile = new File("/Users/liam/Desktop/binary.txt");

        myFile.open("w");

        myFile.encoding = "UTF-8";

        myFile.write(binary);

        myFile.close();

$.writeln(binary);

f.close();

However when a text file is generated it is filled not with the binary data but with this - (new String("")) - which I am led to believe is the result of an incorrect file path.

So in using the original code I posted I thought It may generate the correct (or different) file path.

Hope thats makes sense and thanks again for your time.

Thanks

Liam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 08, 2019 Jul 08, 2019

I just gave it a quick test - your snippet is somewhat buggy - on line 1 you are specifying the path to the image file, but on line 2 you are appending file name. And therefore ESTK cannot find such file - it does not exist.

To be safe, you should check if the file exists before reading it. So if you added this on line 3, you'd get a message saying that such file does not exist

if (!f.exists) {

    return alert('File ' + f.fsName + ' does not exist');

}

That's why the result was just (new String(""))

However, if you are writing a method to convert files into binary strings - don't sweat it, cause I've got such method that's available for everyone to use. Check it out Convert to Binary

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 08, 2019 Jul 08, 2019
LATEST

Ah thank you Tomas, that make sense on why its not found.

Also Convert to Binary is brilliant!

Thanks again!

Liam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 08, 2019 Jul 08, 2019

I found another piece of code from Peter Krahels excellent PDF on UI's

var infile = File ("/Users/liam/Desktop/Thumb.png");

var outfile = File ("/Users/liam/Desktop/icon.txt"); infile.open ("r");

infile.encoding = "binary";

var temp = infile.read(); infile.close();

outfile.open ("w");

outfile.write (temp.toSource ()); outfile.close ();

I have used this instead of the above and it is giving me the desired outcome..

What would be wrong with the previous code?

Thanks

Liam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines