I thank you for the time you dedicated to me I don’t know what to answer I’m sorry.
I verified that the original code still works.
- macOS 12.7.3 (Apple Silicon)
- Photoshop 2024 (25.4.0)
sttk3 I just copied and pasted your code, So I have a doubt that the problem could be in the manifest. However, I thank you again for all the time you dedicated to me, and I’m sorry that I’m not yet that prepared in this type of UXP programming.
It appears that UXP scripts (*.psjs) are no longer executed via app.open() unless the file PSUserConfig.txt contains the setting WarnRunningScripts 1.
It fails silently if the file is not present or WarnRunningScripts is set to 0.
What if you change dialog mode in DOM to display dialogs? Does it get you the prompt dialog?
Dialog mode in the DOM? Isn’t this only supported in BatchPlay?
I tested it using BatchPlay with object set to “open” and dialogOptions to “display”. Not working.
Searching for a different way to execute UXP scripts without the warning dialog. ![]()
Damn, after thinking about it I confused “DOM” with “API”. Time to take a break.
A small update. Now automatically detects the folder where PSUserConfig.txt is saved (previously, it used a replacement table to match the Photoshop version 25 with the suffix ‘2024’, but now it calculates the value)
const photoshop = require('photoshop') ;
const { app, core } = photoshop ;
const fs = require('fs') ;
const { localFileSystem } = require('uxp').storage ;
const os = require('os') ;
const homePath = os.homedir() ;
/**
* Returns path to PSUserConfig.txt
* @return {string}
*/
const getPSUserConfigPath = () => {
const psVersion = require('uxp').host.version ;
const mainVersion = psVersion.split('.')[0] ;
const yyyy = (Number(mainVersion) + 1999).toString() ;
let preferencesPath ;
if( /darwin/i.test(os.platform()) ) {
// macOS
preferencesPath = path.join(homePath, 'Library', 'Preferences', `Adobe Photoshop ${yyyy} Settings`) ;
} else {
// Windows
preferencesPath = path.join(homePath, 'AppData', 'Roaming', 'Adobe', `Adobe Photoshop ${yyyy}`, `Adobe Photoshop ${yyyy} Settings`) ;
}
const userConfigPath = path.join(preferencesPath, 'PSUserConfig.txt') ;
return `file:${userConfigPath}` ;
} ;
/**
* Returns srcPath exists or not
* @return {boolean}
*/
const exists = (srcPath) => {
let res = false ;
try {
fs.lstatSync(srcPath) ;
res = true ;
} catch(e) {
// skip
}
return res ;
} ;
/**
* Returns whether or not to warn when script is opened in Photoshop
* @return {boolean}
*/
const getWarnRunningScripts = () => {
let res = true ;
const userConfigPath = getPSUserConfigPath() ;
if(exists(userConfigPath)) {
const configText = fs.readFileSync(userConfigPath, {encoding: 'utf-8'}) ;
const matchObj = configText.match(/(WarnRunningScripts +)([01])/) ;
if(matchObj[2]) {
res = Boolean(Number(matchObj[2])) ;
}
}
return res ;
} ;
/**
* Set whether or not to warn when script is opened in Photoshop
* @param {boolean | integer} bool new value
*/
const setWarnRunningScripts = (bool) => {
const newValue = parseInt(Number(Boolean(bool))).toString() ;
const userConfigPath = getPSUserConfigPath() ;
let newText ;
if(exists(userConfigPath)) {
const oldText = fs.readFileSync(userConfigPath, {encoding: 'utf-8'}) ;
const pattern = /(WarnRunningScripts +)([01])/ ;
if(pattern.test(oldText)) {
newText = oldText.replace(pattern, `$1${newValue}`) ;
} else {
newText = `${oldText}\nWarnRunningScripts ${newValue}` ;
}
} else {
newText = `WarnRunningScripts ${newValue}` ;
}
try {
fs.writeFileSync(userConfigPath, newText, {encoding: 'utf-8'}) ;
} catch(e) {
// skip
}
} ;
/**
* Execute script file via app.open
* @param {string} targetPath script path e.g. 'file:/Users/username/Desktop/script.psjs'
*/
const execScriptViaOpen = async (targetPath) => {
if(getWarnRunningScripts()) {
// If script warnings are enabled, disable them and require user to restart
setWarnRunningScripts(false) ;
app.showAlert('Restart Photoshop once to execute scripts.') ;
} else {
const scriptEntry = await localFileSystem.getEntryWithUrl(targetPath) ;
app.open(scriptEntry) ;
}
} ;
const main = async () => {
try {
await core.executeAsModal(
async (context) => {
await execScriptViaOpen( path.join(`file:${homePath}`, 'Desktop', 'alert.psjs') ) ;
},
{
'commandName': 'execScriptViaOpen'
}
) ;
} catch(e) {
console.log(e) ;
}
} ;