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

Photoshop script: Environment variables for macos

Community Beginner ,
Jul 06, 2021 Jul 06, 2021

Hi, I have a photoshop scripts that creates UI and saves user's UI preferences to a text file.


I have only tested this on Windows and get the preferences path like this:

    var userdir = $.getenv("LOCALAPPDATA")
    var prefsDir = Folder(userdir + "/PhotoshopScripts");
    var prefFile = File(prefsDir + "/ToolSettings.ini")   

My question is - will this work on a mac? Is there a different way to get environment variables on a mac? 

Also would appreciate suggestions on where people would usually save a prefs file on a mac. Would something under $HOME work?

TOPICS
Actions and scripting
1.0K
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
Adobe
Community Beginner ,
Jul 06, 2021 Jul 06, 2021

I can't seem to edit my question, but I wanted to ask - is there a way to check which OS I'm on so I can use the appropriate environment variable?

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
Community Expert ,
Jul 06, 2021 Jul 06, 2021

I don't know about the best place to save a pref file on a Mac, as I'm on Windows, but here's how to detect if the computer is a Mac:

function IsMacintoshOS() {
	if ( $.os.search(/macintosh/i) != -1 ) {
		return true;
	} else {
		return false;
	}
}
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
Community Beginner ,
Jul 08, 2021 Jul 08, 2021

Thanks! I assume all macs have a /macintosh/ path 😄 
Hacky, but I'll take it!

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
Community Expert ,
Jul 07, 2021 Jul 07, 2021

Adobe added Plug-in support to Photoshop scripting in CS3 and provided a useful example script you may have used  File>Automate>Fit Image... .  That Script has a dialog and works on PC and Mac.  The Script will record the setting you use in its dialog.  The script can also record the setting you use in its dialog recording an action into the Action steps being recorded. When the Action is played the Action will pass the recorded settings to the script and the Script will bypass displaying its dialog and use the setting recorded into the action.  However, if you turn on the Action step dialog in the Action step  the script will display its dialog and pre-fill the dialog settings with the settings recorded in the action step which you can interactivity change or accept.    If you use the Fit Image Plug-in from Photoshop UI File>Automate>Fit Image... it will always display its dialog and pre-fill the dialog settings with  the setting you last when you used the script from Photoshop UI.  So Scripts cans Save save parameters and script can also retrieve information about document and system environment like OS and OS environment variables and also  have custom Photoshop options.   Look at the example scripts in Photoshop Preset scripts and the examples in the Scripting downloaded examples.  For Coding examples

image.png

JJMack
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
Community Beginner ,
Jul 08, 2021 Jul 08, 2021

Thanks! I'll check those out

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
LEGEND ,
Jul 07, 2021 Jul 07, 2021

Did you read: 'JAVASCRIPT TOOLS GUIDE' provided with Extendscript Toolkit from Help menu?

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
Community Beginner ,
Jul 08, 2021 Jul 08, 2021
LATEST

Oh, thanks for the tip! I didn't check this document - just the Javascript guide. Good to know about the shortcut from ExtendScript as well.

I found this:
A path name can start with a tilde (~) to indicate the user’s home directory. It corresponds to the platform’s
HOME environment variable.

 

That's super useful. I'll try it over the weekend. 

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