Skip to main content
Inspiring
August 5, 2019
Question

User TEMP folder. Mac & PC

  • August 5, 2019
  • 3 replies
  • 5129 views

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

This topic has been closed for replies.

3 replies

Participant
November 14, 2021

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

 

JJMack
Community Expert
Community Expert
August 5, 2019

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

JJMack
karpiyonAuthor
Inspiring
August 5, 2019

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");

}

JJMack
Community Expert
Community Expert
August 5, 2019

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...


I believe Mac has an environment variable TMPDIR

 

Searching here I found this It may just be a something 

 

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.

JJMack
Stephen Marsh
Community Expert
Community Expert
August 5, 2019

I’d need a working code snippet to test.