Copy link to clipboard
Copied
Hi,
Does anyone of you knows to convert this:
"/Users/user/Desktop/myFile.ext"
into
"Macintosh HD:Users:user:Desktop:myFile.ext"
Starting from a File myFile.ext located on the desktop ?
I can do string concatenations and stuff or call applescript but I was looking at something more meaningful.
TIA
Loic
Hi Loic,
How about:
f = new File(Folder.desktop + "/myFile.ext");
alert("Macintosh HD" + f.fsName.replace(/\//g, ":");
Ariel
Copy link to clipboard
Copied
Hi Loic,
How about:
f = new File(Folder.desktop + "/myFile.ext");
alert("Macintosh HD" + f.fsName.replace(/\//g, ":");
Ariel
Copy link to clipboard
Copied
Well I guess I will go with this one
Thx
Loic
Copy link to clipboard
Copied
Hi Ariel,
I would feel a little bit uneasy with this.
On Mac OSX file names like shown in the screenshot below are also possible:
( "Schreibtisch" => "Desktop" )
Placed as linked text files with InDesign on OSX showing in the Links panel:
If I am using menu $ID/#LinksUICopyPlatformPath I get this with my text editor which is looking very promissing:
Macname:Users:Username:Desktop:my/\File.txt
Macname:Users:Username:Desktop:my\/File.txt
And indeed, if I am looping the links and ask for filePath values I get exactly the results from above:
var doc = app.documents[0];
var links = doc.links.everyItem().getElements();
for(var n=0;n<links.length;n++)
{
$.writeln(n+"\t"+links
.filePath); };
/*
Result:
0 Macname:Users:Username:Desktop:my/\File.txt
1 Macname:Users:Username:Desktop:my\/File.txt
*/
I'm not so sure with your code.
Hope I interpret it right. Correct me if I'm wrong.
We have a File object do fsName on it and run a RegExp where a slash is replaced by a colon.
And in front of the result string we add the name of the machine:
var doc = app.documents[0];
var links = doc.links.everyItem().getElements();
for(var n=0;n<links.length;n++)
{
$.writeln(n+"\t"+"Macname"+File(links
.filePath).fsName.replace(/\//g, ":")); };
/*
Result:
0 Macname:Users:Username:Desktop:my:\File.txt
1 Macname:Users:Username:Desktop:my\:File.txt
*/
The result is not looking good…
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe,
It is not best practice to use slashes in filenames on the Mac: OS X: Cross-platform filename best practices and conventions - Apple Support
If Loic wishes to account for users who are using slashes nevertheless, I guess the thing to do would be to run the GREP on just the path part of the name and then add the file name. Something like this, I suppose (untested):
f = new File(Folder.desktop + "/myFile.ext");
alert("Macintosh HD" + f.parent.fsName.replace(/\//g, ":") + ":" + f.name);
Ariel
Copy link to clipboard
Copied
Hi guys,
No need to tear your heads off on this one. It's a very specific need. A scriptable plugin defines some function argument to be a HFS path. I was wondering if there was any predictable way of turning a file path into a HFS path like a non revealed method File.toHFS()
There will be one user (my client) so I can presume the context but It would have been nice to be agnostic.
Loic
Copy link to clipboard
Copied
Hi All,
While I agree with Ariel that anyone who uses / or \ in a filename deserves at very least to have his system explode regardless of whether his using Mac, Android, Commodore 64 or Sinclair ZX8.
The above suggested solution however is not to great (even if it satisfies Loic).
My Mac has 2 internal hard drives, 2 external hard drives (Partition to into 6 partitions) and about 6 server drives. Ok. that might be an overkill but that's how it is. Only one of them is called "Macintosh HD".
Anyways if one on InDesign then one can user this simple POSIX to HFS conversion.
It will even handle cases that don't deserve to be taken care of, (Maybe it will fail if the name contains a " in it but that would not be tough to take care of)
var f, as;
f = Folder.desktop; // change as needed
as = 'POSIX file "' + f.fsName + '" as Unicode text';
alert(app.doScript(as, ScriptLanguage.APPLESCRIPT_LANGUAGE));
Hope that helps someone, regards,
Trevor
Copy link to clipboard
Copied
Hi Trevor,
Ariel's solution was fine for my really specific context. Yours extends the scope which is fine but this is typically what I wish I could avoid meaning relying on the context (like using applescript). I just think there isn't any universal and agnostic solution.
Thanks anyway
Loic
Copy link to clipboard
Copied
hi Trevor
Just to let you know that I will use this line of AS Code in my current project. So it was a great addition
Copy link to clipboard
Copied
Thanks for letting me know.
Copy link to clipboard
Copied
You can pass an array of arguments thru app.doScript, no need to convert the Folder to a literal.
Apparently this even works if you omit the UndoMode parameter.
Besides the file/folder argument is already passed as alias or similar, so we can omit the "POSIX file" coercion.
alert(app.doScript("item 1 of arguments as Unicode text", ScriptLanguage.APPLESCRIPT_LANGUAGE,[Folder.desktop]));
Copy link to clipboard
Copied
Use pathfinder - right-click on the folder and copy path as HFS .