Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it work for Indesign? #1

Closed
vanwoods opened this issue Apr 27, 2023 · 10 comments
Closed

Make it work for Indesign? #1

vanwoods opened this issue Apr 27, 2023 · 10 comments

Comments

@vanwoods
Copy link

Hi,

First, thanks for this really handy workflow!

The workflow returns an error trying to make it work for InDesign. Only the last part when executing the script returns an error, the rest works fine the same as the AI and PS part. Do you know how to modify it to make it work the same way for InDesign?

It now produces this error, see below:
Scherm­afbeelding 2023-04-27 om 18 09 11

I'm guessing InDesign handles the scripts differently? The scripts all work when used directly from InDesign, so they seem to be fine.

Hope you can help?

@vanwoods
Copy link
Author

The scripts scope is now at
~/Documents/Scripts/ID/1_SD_SCRIPTS/
and returns the scripts in alfred search field but don't execute

I tried accessing them directly from:
~/Library/Preferences/Adobe InDesign/Version 18.0/en_GB/Scripts/Scripts Panel/1_SD_SCRIPTS/
but that gives no result when searching for scripts. I put this path in alfred search scope but with no result

@joonaspaakko
Copy link
Owner

joonaspaakko commented Apr 27, 2023

The script relies on the applications ability to open a script file via similar to how you'd open any file via File > Open, then recognize it as a script and act accordingly. As far as I know AI and PS are the only ones that do this. Essentially Indesign just doesn't know what to do with the script file with that same command...

I think it should be possible. Quick googling says Indesign AS has a command called do script and you'd use it something like this:

tell application "Adobe InDesign 2020"
	activate
	set jsx_script to "...Desktop:HelloWorld.jsx"
	set a to "Foo"
	set b to "Bar"
	set my_values to {a, b}
	do script jsx_script language javascript with arguments my_values
end tell

For the purpose of this workflow you'd pretty much have to replace the part on the current workflow Applescript that says open scriptFile using appPath with the line that says do script.... It's not quite that simple but generally speaking....

I'll take a look at it this weekend, if I have time. Though not to get your hopes up too much, I did see a lot of people complaining about it not working in few of the more recent Marcos versions.

@vanwoods
Copy link
Author

Thanks for your quick reply!

I changed the AS script to:

on run argv
	
	set appName to (system attribute "targetApplication") --Alfred variable
	set frontMostVar to (system attribute "frontMost") --Alfred variable
	set scriptFile to POSIX file (item 1 of argv)
	
	tell application "System Events"
		set targetApp to application file of (first application process whose name contains appName)
		set appPath to path of targetApp
		set appName to name of targetApp
	end tell

	if frontMostVar is "true" then
		if application appName is frontmost then
			tell application "Finder"
				do script jsx_script language javascript with arguments my_values
			end tell
		end if
	else 
		tell application "Finder"
			do script jsx_script language javascript with arguments my_values
		end tell
	end if
	
end run

No error notification anymore but nothing happens in InDesign either.
I'll try and look if i can find something more about the do script.

Thanks for now!

@joonaspaakko
Copy link
Owner

joonaspaakko commented Apr 28, 2023

I will take a proper look sooner or later, but if I were to play around with it, I would take the simplest example of do script and try to run that in the native /System/Applications/Utilities/Script Editor.app:

tell application "Adobe InDesign 2023"
  set jsx_script to "/Users/joonaspaakko/Dropbox/Adobe scripts/Indesign/MultiPageImporter2.5-CS5.jsx"
  do script jsx_script language javascript
end tell

Couple pointers about your attempt:

  • Since you used that one line only (like I said you should), the my_values variable was never set, so that would cause an error. But in this case that whole tail end is unnecessary: with arguments my_values
    • It can be useful, but only if you wanted to feed it external arguments. Like imagine yourself typing in the filename in Alfred and that gets passed on to the script as it launches, which in turn uses it to save the file. But that is kinda advanced and totally unnecessary with this setup.
  • You need to tell the application Indesign to do script. Right now it's telling Finder to launch the script.
  • The first greater than symbol in the Alfred workflow chain defines an integral part of the script, so that would need to be changed to Adobe Indesign
image

I'd guess it would have to be something like this:

Firstly, this code is not tested. Also, as I mentioned before, searching for info on do script, I found quite a few posts that said it doesn't work anymore since X version of MacOS. None of this code matters if the simple code doesn't run successfully.

on run argv
	
	set appName to (system attribute "targetApplication") --Alfred variable
	set frontMostVar to (system attribute "frontMost") --Alfred variable
	set scriptFile to POSIX file (item 1 of argv)
	set isIndesign to appName is "Adobe Indesign"
	
	tell application "System Events"
		set targetApp to application file of (first application process whose name contains appName)
		set appPath to path of targetApp
		set appName to name of targetApp
	end tell
	
	if frontMostVar is "true" then
		if application appName is frontmost then
			if isIndesign then
				tell application appName
					do script scriptFile language javascript
				end tell
			else
				tell application "Finder"
					open scriptFile using appPath
				end tell
			end if
		end if
	else
		
		if isIndesign then
			tell application appName
				do script scriptFile language javascript
			end tell
		else
			tell application "Finder"
				open scriptFile using appPath
			end tell
		end if
	end if
	
end run

Here's what I changed from the original:

on run argv
	
	set appName to (system attribute "targetApplication") --Alfred variable
	set frontMostVar to (system attribute "frontMost") --Alfred variable
	set scriptFile to POSIX file (item 1 of argv)
+	set isIndesign to appName is "Adobe Indesign"
	
	tell application "System Events"
		set targetApp to application file of (first application process whose name contains appName)
		set appPath to path of targetApp
		set appName to name of targetApp
	end tell
	
	if frontMostVar is "true" then
		if application appName is frontmost then
+			if isIndesign then
+				tell application appName
+					do script scriptFile language javascript
+				end tell
+			else
				tell application "Finder"
					open scriptFile using appPath
				end tell
+			end if
		end if
	else
		
+		if isIndesign then
+			tell application appName
+				do script scriptFile language javascript
+			end tell
+		else
			tell application "Finder"
				open scriptFile using appPath
			end tell
+		end if
	end if
	
end run

@vanwoods
Copy link
Author

Thanks for taking the time to point me out with your feedback!

Activating a fixed script directly is no problem and works, also from Alfred (in the simple code version, see attached workflow with keyword 'idl'). But when I try to combine this in your workflow it still doesn’t execute/activates the scripts (even with the fixed path to a script). So do script does work, but i can't figure out how to combine it. Could it have something to do with set to part of the script?

I've tried:

  • Used Adobe Indesign in different ways ('Adobe Indesign', 'Adobe InDesign', 'Adobe InDesign 2023'
  • Added jsxbin to the filetypes (also doesn't execute)
  • A fixed path of the script (not working)

ID scripts launcher.zip

@joonaspaakko
Copy link
Owner

joonaspaakko commented Apr 29, 2023

I updated the repo with a new workflow file where the Indesign script launching seems to now be working fine.

The issue with my untested code was that apparently application specific methods like the do script in this instance, can't be used if the tell application "name" comes from a variable. I couldn't really find much info on that, but that's how it seems to work. So I settled with identifying Indesign with its bundle id. This should work better than having to change the static application name every year (Adobe Indesign 2023, Adobe Indesign 2024, etc..), though that said I wasn't able to test how the bundle identifier works when a new version of the app is installed, let alone what happens if multiple versions are installed. I'd think it would use the latest install, but that is just a guess.

I did a lot of testing with various setups and so I'm no longer sure what the workflow will do on the first Indesign script launch, but at some point during my tests it asked me to pick Indesign from a list of applications so it knows what application to launch the script on and there was also some kind of accessibility permission prompt at some point, but those were one time things, after which the workflow worked just like it did for AI and PS.

@vanwoods
Copy link
Author

Thanks for taking the time trying to fix this. Only I can't get this to work, also the AI and PS part doesn't work anymore in this new workflow. I granted access in the automation part in security and privacy tab in system preferences. See picture below.

Screenshot 2023-04-30 at 22 36 44

The old workflow for only PS and AI still works fine, i'm getting the scripts out of the same scope.

Any idea what i could be missing?

This is the outcome of the debugger:

[23:05:12.097] CC Scripts Launcher[File Filter] Processing complete
[23:05:12.104] CC Scripts Launcher[File Filter] Passing output '/Users/patrick/Documents/Scripts/ID/1_SD_SCRIPTS/MultiPageImporter2.5JJB.jsx' to Arg and Vars
[23:05:12.105] CC Scripts Launcher[Arg and Vars] Processing complete
[23:05:12.106] CC Scripts Launcher[Arg and Vars] Passing output '/Users/patrick/Documents/Scripts/ID/1_SD_SCRIPTS/MultiPageImporter2.5JJB.jsx' to Arg and Vars
[23:05:12.107] CC Scripts Launcher[Arg and Vars] Processing complete
[23:05:12.109] CC Scripts Launcher[Arg and Vars] Passing output '/Users/patrick/Documents/Scripts/ID/1_SD_SCRIPTS/MultiPageImporter2.5JJB.jsx' to Run Script
[23:05:12.224] ERROR: CC Scripts Launcher[Run Script] /Users/patrick/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/1E014E04-52DF-44BF-B581-79E093881F89:709:715: script error: Expected end of line, etc. but found “script”. (-2741)

@joonaspaakko
Copy link
Owner

I updated the workflow file again.

I split the AppleScript action so that Indesign uses its own. If it still doesn't work, it won't affect AI and PS. I switched from the bundle id to the static application name string, which should now work, but requires manual updating every year when your Indesign updates.

If you're interested...

It was the same issue it's been from the beginning Expected end of line, etc. but found “script”. - It doesn't understand the do script because it's a "custom" method that is specific to Indesign, which it still didn't seem to understand with the bundle id, so I switched it to the static string tell application "Adobe InDesign 2023". The way Alfred tells you about the error makes it harder to locate. In the Script Editor.app it shows you exactly what it's talking about:

@vanwoods
Copy link
Author

vanwoods commented May 2, 2023

I found the solution to still use the bundle id, which is of course better. Place 'id' after 'tell application'

tell application id "com.adobe.InDesign"

When InDesign script is launched it still says Photoshop scripts, i can fix this myself but you probably want to update your workflow here.

Thanks for your help, great to launch InDesign scripts this way!

@joonaspaakko
Copy link
Owner

Good, I was pretty crushed when I thought I had to use a static string. I updated the repo with your suggested fixes.

@joonaspaakko joonaspaakko pinned this issue Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants