[Solved] Job disappears during Process of passing it to AppleScript
Posted: Mon Apr 08, 2024 11:46 am
Hello,
I'm trying to develop a Switch-Script that allows me to use multiple Photoshop-versions (as it is not possible with the existing Photoshop App). So my Script is passing a Job to AppleScript, which then runs a jsx-Script that opens the Job in a certain Photoshop version.
The Problem is, that the Job somehow get's lost during that Process. I can see a Folder of the Job appear at:
/private/var/folders/_c/hrdmw2956p18z28dnjkts68j9k31pl/T/SwitchNodeScriptExecutor
when running the TypeScript and after about a second it disappears, which is why the jsx-Script is not able to open it, as the Path of the Job no longer exists.
Before running the AppleScript I check for the existence of the File in TypeScript. At that moment the File does indeed exist.
At first I was trying to run the AppleScript-Code directly inside of my TypeScript by using the node-osascript Package. So I thought that the Package would cause the Problem. Then I wrote a separate AppleScript scpt File which still resulted in the same Problem. I even checked for the File inside of the AppleScript which tells me that it does not exist.
This is the part of the TypeScript-Code that runs the AppleScript. I didn't include the variables in the Snippet except for the jobPathString-variable:
Do I have to handle the Job differently in my TypeScript so that it doesn't disappear?
I'm trying to develop a Switch-Script that allows me to use multiple Photoshop-versions (as it is not possible with the existing Photoshop App). So my Script is passing a Job to AppleScript, which then runs a jsx-Script that opens the Job in a certain Photoshop version.
The Problem is, that the Job somehow get's lost during that Process. I can see a Folder of the Job appear at:
/private/var/folders/_c/hrdmw2956p18z28dnjkts68j9k31pl/T/SwitchNodeScriptExecutor
when running the TypeScript and after about a second it disappears, which is why the jsx-Script is not able to open it, as the Path of the Job no longer exists.
Before running the AppleScript I check for the existence of the File in TypeScript. At that moment the File does indeed exist.
At first I was trying to run the AppleScript-Code directly inside of my TypeScript by using the node-osascript Package. So I thought that the Package would cause the Problem. Then I wrote a separate AppleScript scpt File which still resulted in the same Problem. I even checked for the File inside of the AppleScript which tells me that it does not exist.
This is the part of the TypeScript-Code that runs the AppleScript. I didn't include the variables in the Snippet except for the jobPathString-variable:
Code: Select all
async function jobArrived(s: Switch, flowElement: FlowElement, job: Job) {
const { exec } = require('child_process');
const fs = require("fs");
var jobPathString = await job.get(AccessLevel.ReadWrite);
if (fs.existsSync(jobPathString)) {
// File exists in path
await job.log(LogLevel.Info, "File exists in path");
await job.log(LogLevel.Info, "Path: " + jobPathString);
} else {
// File doesn't exist in path
await job.log(LogLevel.Error, "File doesn't exist in path");
}
const appleScriptPath = '/Users/switch/Desktop/logSkript.scpt';
const command = `osascript ${appleScriptPath} "${wrapperScriptPath}" "${photoshopVersion}" "${jobPathString}" "${arg1}" "${arg2}" "${arg3}" "${arg4}" "${arg5}" "${arg6}" "${arg7}" "${arg8}" "${arg9}" "${arg10}" "${arg11}" "${arg12}" "${arg13}" "${arg14}" "${arg15}" "${openScriptPath}" "${processScriptPath}" "${saveScriptPath}"`;
exec(command, (error: Error, stdout: String, stderr: String) => {
if (error) {
console.error(`Fehler beim Ausführen des Skripts: ${error}`);
return;
}
console.log(`Ausgabe: ${stdout}`);
console.error(`Fehlerausgabe: ${stderr}`);
});
}
}