Copy link to clipboard
Copied
Hi folks,
need help with this task: Bringing the active document name to status messages of Messages.
Since I failed with javascript (Messages status got changed but did not show up) I switched to Applescrip for this, which works, but:
If I test my script without Indesign everything is fine ("…and executed"). But if I put it in startup scripts, the event gets fired ("fired…"), but the rest doesnt work anymore. Has InDesign a problem with firing other applications or what is wrong here??
--Registers an event listener on the afterNew event.
tell application "Adobe InDesign CS5.5"
make event listener with properties {event type:"afterOpen", handler:my MessageStatus}
end tell
on MessageStatus()
display dialog "fired…"
set docName to "empty"
tell application "Adobe InDesign CS5.5"
try
tell active document
set docName to name of it as string
end tell
end try
end tell
tell application "Messages"
set the status message to "" & (random number from 1 to 99) & " " & docName
display dialog "…and executed"
end tell
end MessageStatus
Hi,
There is no reasons why applescript wouldn't call an app if accessible. I tried a little snippet of mine and as a startup script, messages app is well run.
...#targetengine "onAfterOpen"
var main = function(){
var ev = app.eventListeners.item("onAfterOpen");
var onAfterOpenHandler = function (evt) {
var doc = evt.parent;
if ( !(doc instanceof Document ) ) return;
callMessage ( doc.name );
}
if ( !ev.isValid ) {
ev = app.eventListeners.add ( "afterOpen", onAfterOpenHandler );
Copy link to clipboard
Copied
Hi,
There is no reasons why applescript wouldn't call an app if accessible. I tried a little snippet of mine and as a startup script, messages app is well run.
#targetengine "onAfterOpen"
var main = function(){
var ev = app.eventListeners.item("onAfterOpen");
var onAfterOpenHandler = function (evt) {
var doc = evt.parent;
if ( !(doc instanceof Document ) ) return;
callMessage ( doc.name );
}
if ( !ev.isValid ) {
ev = app.eventListeners.add ( "afterOpen", onAfterOpenHandler );
ev.name = "onAfterOpen";
}
}
var callMessage = function( docName ) {
var aps = "tell application \"Messages\" ";
aps+="\r"+"set the status message to \"\" & (random number from 1 to 99) & \" \" & \""+docName+"\"" ;
aps+="\rdisplay dialog \"…and executed\"";
aps+="\rend tell";
app.doScript ( aps, ScriptLanguage.applescriptLanguage );
}
main();
HTH
Loic
Copy link to clipboard
Copied
Thank you Loic, thats a wrap! A bit of a downer is porting the script to JS, but I guess i can add some AS to your aps-string. I changed the handler to afterActivate, to catch switching between opened docs. Now I have to think of something to clear the status message when all docs has been closed...
Copy link to clipboard
Copied
you may prefer then afterSelectionChanged handler or use eventListeners on a custom idleTask to check documents length.
FWIW
Loic
Copy link to clipboard
Copied
The key difference between Loic's javascript solution and your as solution is the use of the persistent target engine. Since applescript does not have that ability, at the time the event actually fires, the MessageStatus function is no longer available.
Copy link to clipboard
Copied
Couldn't say it clearer
Copy link to clipboard
Copied
In the AS-AdobeScriptingGuide CS6 about AS event handlers, i saw them call a external script…
--Registers an event listener on the afterNew event.
tell application "Adobe InDesign CS6"
make event listener with properties {event type:"afterNew", handler:"yukino:IDEventHandlers:AfterNewHandler.applescript"}
end tell
Wouldnt this do the trick also, to put the name-getting and message-telling there?
Copy link to clipboard
Copied
It should, but my knowledge of AS is very limited. Try it and see what happens.
Copy link to clipboard
Copied
It's mostly of point of view but I always put javascript first and keep Applescript/VisualBasic for when I really need it. Applescript is fine for basic to medium operations but for advanced stuff…no thanks.
Copy link to clipboard
Copied
Its a matter of skill for me, since the syntax is nearly full text and easy to read. I'm no coder, and more like an copy/paste-coder, but really a graphic/layout-guy, who wants to simplify his workflow. But I got some things codes that run very well, not slick, but very useful for me and my collegues. I know the benefit of JS over AS to use multiplatform, and got me this to help me get into JS… http://www.indiscripts.com/post/2015/12/indesign-automatisieren-scripting-bible-in-german …but my boss makes me build flyers and doesnt want to benefit from my scripting-curiosity 😕
Copy link to clipboard
Copied
I had this kind of job issue where no one understood what scripting could bring and why it was worth automating things. Well that's when I chose to stand on my own two feet
Once that said, it's not all about having a script that can be run over two os. It's also that as you said Applescript has been designed more like a english spoken language than a programming language. It's helpful for non programmers and basic operations. I don't doubt there are some APS gurus that can do amazing stuff. But Javascript (and probably VB) is more a programming language which allows code optimization.
I use some routines that are trivial in JS and would require hundreds of lines in APS.
You should really consider a switch step by step