Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
}
}
Copy link to clipboard
Copied
Thanks! I assume all macs have a /macintosh/ path 😄
Hacky, but I'll take it!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks! I'll check those out
Copy link to clipboard
Copied
Did you read: 'JAVASCRIPT TOOLS GUIDE' provided with Extendscript Toolkit from Help menu?
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now