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

User TEMP folder. Mac & PC

Engaged ,
Aug 05, 2019 Aug 05, 2019

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

TOPICS
Actions and scripting

Views

4.6K

Translate

Translate

Report

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
Adobe
Community Expert ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

I’d need a working code snippet to test.

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

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

JJMack

Votes

Translate

Translate

Report

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
Engaged ,
Aug 05, 2019 Aug 05, 2019

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

}

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

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

JJMack

Votes

Translate

Translate

Report

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
Engaged ,
Aug 05, 2019 Aug 05, 2019

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

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

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,''));

 

 

 

Kukurykus_0-1636898367959.png

 

 

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

 

Kukurykus_1-1636898367961.png

 

Kukurykus_2-1636898367962.png

 

 

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

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

JJ, those path locations are old, and will not work with Win 10.

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

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
JJMack

Votes

Translate

Translate

Report

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
Engaged ,
Aug 07, 2019 Aug 07, 2019

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

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

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

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

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.

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

Thanks Chuck, this is what I get with macOS Mojave 10.14.5:

path.png

However I also see:

/private/var/tmp

Votes

Translate

Translate

Report

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
LEGEND ,
Aug 05, 2019 Aug 05, 2019

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.

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

I am new to scripting, so the only cross-platform folder that I know of is:

var saveFolder = "~/Desktop";

Votes

Translate

Translate

Report

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
New Here ,
Nov 13, 2021 Nov 13, 2021

Copy link to clipboard

Copied

LATEST

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

 

Votes

Translate

Translate

Report

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