Copy link to clipboard
Copied
Hi,
In my script i write some data to:
File($.getenv("TEMP")
This is working for PC.
Is this the correct variable for user tempo dir on MAC?
Dan
Copy link to clipboard
Copied
I’d need a working code snippet to test.
Copy link to clipboard
Copied
Read the JavaScript-Tools-Guide-CC.pdf about the differences between PC and Mac files systems Temp will work on PC I doe not know where users temp file would be on a Mac
Copy link to clipboard
Copied
Then what would you use as a writable temp folder on mac?
os = $.os.toLowerCase().indexOf('mac') >= 0 ? "MAC": "WINDOWS";
if(os == "WINDOWS"){
var tmpFile = File($.getenv("TEMP") + "/tmpFile.txt");
}else{
var tmpFile = File(??? + "/tmpFile.txt");
}
Copy link to clipboard
Copied
I do not know what convention Apple OS may have for temp space and files. Use google I see this
Where’s the Temp Folder on Mac OS? How to Find & Open the Mac Temporary Directory
Copy link to clipboard
Copied
Thanks,
i'll use this:
var os = $.os.toLowerCase().indexOf('mac') >= 0 ? "MAC": "WIN";
if(os == "WIN"){
var tmpFile = File($.getenv("TEMP") + "/Tmp.txt");
}else{
var tmpFile = File("/tmp/Tmp.txt");
}
I just need to test this and for this I need a MAC...
Copy link to clipboard
Copied
I believe Mac has an environment variable TMPDIR
Searching here I found this It may just be a something Michael L Haleon Feb 6, 2013 12:51 AM in Get root directory/drive in response to dgolberg used for his personal environment
var Mac = new File("/Users/USERNAME/Dir/tmpDir/file.psd").fsName;
var Win = new File("/C/Documents and Settings/USERNAME/Dir/desktop/file.psd").fsName;
alert(Mac.match(/^[\/\w]?[\/\w\s]*?[:\/]/).toString().replace(/[:\/]/g,''));
alert(Win.match(/^[\/\w]?[\/\w\s]*?[:\/]/).toString().replace(/[:\/]/g,''));
So
if (os == "WIN") var tmpFile = new File( "/~/AppData/Local/Temp/" + filename)
There is Folder class properties
I have used this one Windows. I do not know if Folder.temp is valid on a Mac it may be I have not receive bug reports about my scripts that use it. However I do not know how download a uset my scripts. I get little feedback here Photoshops forums. I just Hack at scripting.
var batch_file = new File(Folder.temp + "/send_email.bat");
I see Folder.temp used in many places in XTools and no test before its use for Mac or PC. It may be cross platform.
Copy link to clipboard
Copied
JJ, those path locations are old, and will not work with Win 10.
Copy link to clipboard
Copied
On Windows
alert(Folder.temp);
resolves to this I have noo Access to a Mac I would like to know what it does on a Mac
I believed this worked on my son's Mac years ago. He now has a Microsoft Studio 2.
var URL = new File(Folder.temp + "/PhotoCollageToolkit.html");
URL.open("w");
URL.writeln('<html><HEAD><meta HTTP-EQUIV="REFRESH" content="0; url=http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html"></HEAD></HTML>');
URL.close();
URL.execute(); // The temp file is created but this fails to open the users default browser using Photoshop CC prior Photoshop versions work
Copy link to clipboard
Copied
I installed a virtual MAC machine to test my scripts and panel on a MAC.
$TMPDIR is a writable temp dir on mac
Copy link to clipboard
Copied
Running the script in ESTK targeting both ESTK and Photoshop, I could not find that path, directory or file (macOS Mojave 10.14.5).
Copy link to clipboard
Copied
Stephen, if you have a MAC, create a smart object, open it then run this code to check the path:
alert(activeDocument.path);
Once you get the path, you should be able to replace the first part of the path with the ~ to direct it to the user's personal folder, where I believe the temp folders are located. Here it is on Win.
Copy link to clipboard
Copied
Thanks Chuck, this is what I get with macOS Mojave 10.14.5:
However I also see:
/private/var/tmp
Copy link to clipboard
Copied
Both of these will be temporary folders. Recent versions of Mac OS create a unique folder for unsigned apps, with a copy of the app, including its own private temporary area. On all Unix based systems, /tmp is a writeable temporary folder, but this is not the one used by Apple's own APIs. Whatever it is, don't expect there to be a temporary folder or an API to locate it...
By the way, Mac does provide a suitable environment variable, because it's POSIX compliant. Please start a command tool and type env to see the environment variables for a normal user.
Copy link to clipboard
Copied
I am new to scripting, so the only cross-platform folder that I know of is:
var saveFolder = "~/Desktop";
Copy link to clipboard
Copied
You can use the following code to get the Platform-Specific path of Default Temporary folder:
var tempFolder = Folder.temp.fsName;
alert(tempFolder); // Check the Path of Folder