How to execute an InDesign extendscript from command line? - command-line

I need to execute a .jsx script for InDesign from command line (Windows).
For Illustrator, it works easily with the following command:
"C:\Program Files\Adobe\Adobe Illustrator CS6 (64 Bit)\Support Files\Contents\Windows\Illustrator.exe" "...\myscript.jsx"
Both applications Illustrator and ExtendScript Toolkit CS6 open then the script is automatically launched.
When I try the same for InDesign, it doesn't work (InDesign says 'Unable to open myscript.jsx ...').
I also tried to launch ExtendScript Toolkit from command line as below:
"C:\Program Files (x86)\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\ExtendScript Toolkit.exe" "...\myscript.jsx"
The result is ExtendScript Toolkit application is opened with the script loaded, but nothing is executed.
Does anyone know how to launch the script? Is there a -run or -cmd argument to add?

For me on Osx it works like this:
/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOS/ExtendScript\ Toolkit -run test.jsx
On Windows it should be:
"\path\to\ExtendScript Toolkit.exe" -run test.jsx
content of test.jsx:
//#target indesign
alert(app.name);
It needs the -run flag. When using -cmd it still executes the script but from ESTK. The //#target indesign gets ignored. With the -run the script gets passed to InDesign. Unfortunately the ESTK brings up a dialogue that warns to execute scripts from untrusted sources.

a solution of yours could be to call a visualbasic script from command line. That VB would then call the indesign jsx file based on having referenced teh indesign application itself. Kind of tricky but should definitively work.

If you are trying to execute using node, these are the best two ways I have found to execute Indesign scripts.
Version Agnostic
Credit rendertom inside his vscode/atom plugins.
const outputFilePath = path.resolve(os.homedir(), 'Documents', 'Adobe Scripts', 'myscript.js');
const hostCommand = {
darwin: {
command: 'osascript',
args: [
'-e',
`tell application id "com.adobe.indesign" to do script "${outputFilePath}" language javascript`
],
options: {}
},
win32: {
command: 'powershell',
args: [
'-command',
`"$app = new-object -comobject InDesign.Application; $app.DoScript('${outputFilePath}', 1246973031)"`
],
options: {shell: true} // Windows requires a shell
}
};
if (typeof hostCommand[process.platform] == 'undefined') {
throw new Error('This platform is not supported');
}
const {command, args, options} = hostCommand[process.platform];
const p = spawn(command, args, options);

I don't have Windows at hand to actually test it but I would start by looking at those links:
Run VBS in command line : http://ss64.com/vb/cscript.html
Run InDesign in VB:https://www.google.fr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwjj9_3JoPXMAhVI1BoKHUKMBT8QFggfMAA&url=https%3A%2F%2Fwww.adobe.com%2Fcontent%2Fdam%2FAdobe%2Fen%2Fdevnet%2Findesign%2Fsdk%2Fcs6%2Fscripting%2FInDesign_ScriptingGuide_VB.pdf&usg=AFQjCNFP8M8i3xrOqLp0zw3BGcNpnyhEXQ&sig2=pfFYnsgxXDpCf1A573JTDQ&bvm=bv.122676328,d.d2s
Look at the DoScript method for calling a JSX script.
myInDesign.DoScript myJavaScript,

Without ExtendScript Toolkit and on a Mac, you can use AppleScript or JavaScript for Automation (JXA).
This is how it's done in the jasminejsx library to execute jasmine specs in ExtendScript.
osascript -l "JavaScript" -e "var app = new Application('com.adobe.indesign'); app.doScript('$EXTENDSCRIPT', {language: 'javascript'});" &
See code here.

Related

Add bash script as an entrypoint to Python package with Poetry

Is it possible to add bash script as an entrypoint (console script) to Python package via poetry? It looks like it only accepts python files (see code here).
I want entry.sh to be an entry script
#!/usr/bin/env bash
set -e
echo "Running entrypoint"
via setup.py
entry_points={
"console_scripts": [
"entry=entry.sh",
],
},
On the other hand setuptools seems to be supporting shell scripts (see code here).
Is it possible to include shell script into a package and add it to the entrypoints after installing when working with Poetry?
UPD. setuptools does not support that as well (it generates code below)
def importlib_load_entry_point(spec, group, name):
dist_name, _, _ = spec.partition('==')
matches = (
entry_point
for entry_point in distribution(dist_name).entry_points
if entry_point.group == group and entry_point.name == name
)
return next(matches).load()
globals().setdefault('load_entry_point', importlib_load_entry_point)
Is it design decision? It looks to me that packaging should provide such a feature to deliver complex applications as a single bundle.
So I ended up using this workaround: have my script in place and add it to the bundle via package_data and call it from within Python code which I made as an entrypoint.
import subprocess
def _run(bash_script):
return subprocess.call(bash_script, shell=True)
def entrypoint():
return _run("./scripts/my_entrypoint.sh")
def another_entrypoint_if_needed():
return _run("./scripts/some_other_script.sh")
and pyproject.toml
[tool.poetry.scripts]
entrypoint = 'bash_runner:entrypoint'
another = 'bash_runner:another_entrypoint_if_needed'
Same works for console_scripts in setup.py file.

Spawning language server with cmd`diagnostic-languageserver`failed. The language server is either not installed, missing from PATH, or not executable

enter image description here
" Spawning language server with cmd: diagnostic-languageserver failed. The language server is either not installed, missing from PATH, or not executable "
nvim problem
i copied devaslife's dotfiles and installed plugin
yesterday it work, but today i entered LSP info after that when i Enter shows that the error
I've resolved this problem by executing the below command
npm install -g diagnostic-languageserver
Use this:
yarn global add diagnostic-languageserver
Probably, it's because you have not set up the right programming language that you are using in the lspconfig.rc.vim, precisely in the nvim_lsp.tsserver.setup part.
I had the same problem because I was in javascript file (.js) and the lsp config that I was using from someone else only supports typescript files. So, I just had to add the javascript, javascriptreact and javascript.jsx. For example :
nvim_lsp.tsserver.setup {
on_attach = on_attach,
filetypes = { "typescript", "typescriptreact", "typescript.tsx", "javascript", "javascriptreact", "javascript.jsx" },
capabilities = capabilities
}
That is not working for me. In the lspconfig.re.vim, i had to delete the "javascipt", "javasriptreact", "javascript.jsx" types from the nvim_lsp.diagnosticls.setup/filetypes, and then put them in the nvim_lsp.tsserver.setup>filetypes
For windows you can use this:
nvim_lsp.tsserver.setup {
on_attach = on_attach,
filetypes = { "typescript", "typescriptreact", "typescript.tsx" },
cmd = { "typescript-language-server.cmd", "--stdio" }
}
This will make sure it will run the .cmd file that is along side the .ps1.

Build Unity Server under ubuntu via command line

I created a very simple Unity Server, which uses a simple script (taken from here).
I tried to build it through the ubuntu bash with the following command:
~/Unity/Hub/Editor/2019.4.30f1/Editor/Unity -batchmode -nographics -logfile stdout.log -projectPath /path/to/the/project -buildLinux64Player /project/build/destination -quit
And it worked! It's able to create a working build. The problem is that the 3D windows is displayed as well. I don't want to interact with any game object.
Is there a way to create or run the executable without GUI?
As you can see I used "batchmode" and "nographics" flags which were supposed to prevent the user interface to appear.
Which sort of mistake I have done?
Thanks for your time.
As you can see I used "batchmode" and "nographics" flags which were supposed to prevent the user interface to appear.
yes and it didn't!
However, these two flags only apply to this instance of the UnityEditor which performs the build ... they do not apply to the actual resulting built application ;)
Usually you would go to the BuildSettings and enable
Server Build
Enable this checkbox to build the Player for server use and with no visual elements (headless) without the need for any command line options. When you enable this option, Unity builds managed scripts
with the UNITY_SERVER define, which means you can write server-specific code for your applications. You can also build to the Windows version as a console app so that stdin and stdout are accessible. Unity logs go to stdout by default.
under CommandLine Arguments you can find for how to trigger a scripted build via the console. Instead of using -buildXYZ you could use -executeMethod and within that method define the exact player and build settings you want before starting the build process
#if UNITY_EDITOR
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
class ScriptedBuilds
{
// Invoked via command line only
static void PerformHeadlessLinuxBuild()
{
// As a fallback use <project root>/BUILD as output path
var buildPath = Path.Combine(Application.dataPath, "BUILD");
// read in command line arguments e.g. add "-buildPath some/Path" if you want a different output path
var args = Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length; i++)
{
if (args[i] == "-buildPath")
{
buildPath = args[i + 1];
}
}
// if the output folder doesn't exist create it now
if (!Directory.Exists(buildPath))
{
Directory.CreateDirectory(buildPath);
}
BuildPipeline.BuildPlayer(
// Simply use the scenes from the build settings
// see https://docs.unity3d.com/ScriptReference/EditorBuildSettings-scenes.html
EditorBuildSettings.scenes,
// pass on the output folder
buildPath,
// Build for Linux 64 bit
BuildTarget.StandaloneLinux64,
// Use Headless mode
// see https://docs.unity3d.com/ScriptReference/BuildOptions.EnableHeadlessMode.html
// and make the build fail for any error
// see https://docs.unity3d.com/ScriptReference/BuildOptions.StrictMode.html
BuildOptions.EnableHeadlessMode | BuildOptions.StrictMode
);
}
}
#endif
and then e.g.
~/Unity/Hub/Editor/2019.4.30f1/Editor/Unity -batchmode -nographics -logfile stdout.log -projectPath /path/to/the/project -executeMethod ScriptedBuilds.PerformHeadlessLinuxBuild -quit
or with a custom build output path
~/Unity/Hub/Editor/2019.4.30f1/Editor/Unity -batchmode -nographics -logfile stdout.log -projectPath /path/to/the/project -buildPath path/to/build/destination -executeMethod ScriptedBuilds.PerformHeadlessLinuxBuild -quit
Maybe you could try to add the #define UNITY_SERVER directive to the top of your script. This will enable the server build and disable visual elements see 'Server Build' option in the 'Platform list' table

Can run yarn command from one Power Shell window, but not another. What could possibly explain the difference?

SUCCESS
I start PowerShell from the File explorer: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe. I change directory to where I want to run the yarn command. I run yarn build which starts the script rollup --config --environment NODE_ENV:production. The application builds successfully.
FAIL
I start PowerShell from the start menu: C:\Users\Me\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk. This shortcut targets the executable above: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe. I change directory to where I want to run the yarn command. I run yarn build. The build errors.
src/renderer/renderer.tsx → app/build...
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src\renderer\renderer.tsx (6:9)
4:
5: document.addEventListener("DOMContentLoaded", () =>
6: render(<App />, document.getElementById("root"))
^
7: );
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
at error (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:217:30)
at Module.error (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:15145:16)
at tryParse (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:15034:23)
at Module.setSource (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:15436:30)
at ModuleLoader.addModuleSource (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:17434:20)
at ModuleLoader.fetchModule (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:17495:9)
at async Promise.all (index 0)
at async Promise.all (index 0)
error Command failed with exit code 1.
LOOKING FOR DIFFERENCES
I have checked the file properties of the shortcut. It does not open the target as administrator. The owner is EUR/{Me}. System, Me and Administrators have all permissions checked except for special permissions. I think this is should not lead to any difference in behavior from starting PowerShell without using this shortcut?
I have printed the environment variables on both shells using dir env: | Format-Table -Wrap and they are completely equal.
So now I am scratching my head. What could possibly explain the difference?

Installing an exe with Powershell DSC Package resource gets return code 1619

I'm trying to use Powershell DSC's Package resource to install an exe... Perforce's P4V to be specific. Here's my code:
Configuration PerforceMachine
{
Node "SERVERNAME"
{
Package P4V
{
Ensure = "Present"
Name = "Perforce Visual Components"
Path = "\\nas\share\p4vinst64.exe"
ProductId = ''
Arguments = "/S /V/qn" # args for silent mode
LogPath = "$env:ProgramData\p4v_install.log"
}
}
}
When running this, this is the error Powershell gives me:
PowerShell provider MSFT_PackageResource failed to execute Set-TargetResource functionality with error message: The return code 1619 was not expected. Configuration is likely not
correct
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName : SERVERNAME
According to documentation, return code 1619 means the MSI package couldn't be opened. However, when I manually log in to the machine and run "\\nas\share\p4vinst64.exe /S /V/qn", the install works flawlessly.
Does anyone know why this is failing? Alternately, can anyone tell me how to troubleshoot this? I pasted all the error information I got from the terminal, my log file (p4v_install.log) is a 0 byte file, and there are no events in the event viewer. I don't know how to troubleshoot it any further!
EDIT: I should note that I also tried using the File resource to copy the file locally, and then install it from there. Sadly, that met with the same result.
Daniel over at the Powershell.org forums was able to figure this out for me.
The P4V InstallShield setup wrapper puts the MSI file into wrong path if you execute as LocalSystem.
I’ve managed to develop a Configuration that works, see below. The key is the /b switch here which puts the MSI file into a defined location. I’ve added ALLUSERS=1 to get the shortcuts visible to all users and REBOOT=ReallySuppress to avoid a sudden restart (which will happen otherwise).
Configuration PerforceMachine
{
Package P4V
{
Ensure = "Present"
Name = "Perforce Visual Components"
Path = "C:\My\p4vinst64.exe"
ProductId = ''
Arguments = '/b"C:\Windows\Temp\PerforceClient" /S /V"/qn ALLUSERS=1 REBOOT=ReallySuppress"' # args for silent mode
}
}
Well, what happens here is that the package gets installed (not tested with p4vinst64.exe yet! So, not sure why it says pack cannot be opened as the error) but since you did not specify a ProductID value, the verification at the end of install fails. That is the error you are seeing. The Package resource is no good for installing .exe packages or even MSIs with no ProductID represented as a GUID.
You can use the WindowsProcess resource instead.