Copy link to clipboard
Copied
I'm thinking of the app.system command which can maybe run ps1 scripts through the command line, but the command line would need Bash installed. Is there a way without Bash being installed?
app.system('powershell.exe -ExecutionPolicy bypass -File "e:\\test.ps1"')
Copy link to clipboard
Copied
app.system('powershell.exe -ExecutionPolicy bypass -File "e:\\test.ps1"')
Copy link to clipboard
Copied
You might find this library I wrote helpful, you can save it as a .jsxinc (include) file.
/*
Utility Pack Scripts created by David M. Converse ©2018-21
This script is a sample include file for scripters that contains a
template function to run command line actions in Windows
without the command line window showing. This function takes
either a native Powershell function or command prompt code,
writes it into a vbs file, and executes the vbs file to launch Powershell.
Syntax is critical, note all of the escaped characters!
Last modified 6/3/2021
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
PS Example to create a zip file:
(requires Powershell 5 or later)
//list of files to compress
var inputName = '\'C:\\Users\\test\\Desktop\\foo.txt\', \'C:\\Users\\test\\Desktop\\bar.txt\'';
//name of zip archive
var archName = '\'C:\\Users\\test\\Desktop\\archive.zip\'';
//assembled command
var psParam = 'Compress-Archive -LiteralPath '+ inputName +' -DestinationPath ' + archName;
//send command to function
psCommand(psParam);
*/
/*
Command Example to call the DNG Converter and convert files to DNG:
(requires Adobe DNG Converter in default install path)
//path to DNG Converter
var appPath = '\'C:\\Program Files\\Adobe\\Adobe DNG Converter\\Adobe DNG Converter.exe\'';
//command line arguments
var args = '-c -p1';
//files to process, note escaped quotes
var filePaths = ' \""C:\\Users\\test\\Desktop\\img001.CR2\"" \""C:\\Users\\test\\Desktop\\img002.CR2\""';
//assembled command
var psParam = 'Start-Process -FilePath '+ appPath + ' -ArgumentList \'' + args + filePaths;
//send command to function
psCommand(psParam);
*/
//pass the command
psCommand = function(psParam){
try{
//PS command encapsulated in vbs
var commandStr = 'CreateObject("Wscript.Shell").Run "powershell -NoLogo -NoProfile -Command ' + psParam + '\'", 0, True';
//create temp vbs file in ~\AppData\Local\Temp\
//use forward slash for Extendscript paths
var vbsTempFile = new File(Folder.temp + '/vbstemp.vbs');
//open for write
vbsTempFile.open ('w');
//write command to vbs file
vbsTempFile.write(commandStr);
//close file
vbsTempFile.close();
//execute vbs file
File(vbsTempFile).execute();
//adjust time as required before vbs file is deleted
$.sleep(1500);
//delete vbs file
File(vbsTempFile).remove();
}
catch(e){
//alert on error
alert(e + ' ' + e.line);
}
}