Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to use a keystroke for continuing an applescript?

Community Beginner ,
Feb 22, 2020 Feb 22, 2020

hello,

i'm trying to create an applescript for Indesign for a multi layer document which basically deactivates the current layer and activates the one below upon the ctrl + arrow down key.

is this possible?

rené bosch

TOPICS
Scripting
585
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2020 Feb 22, 2020

Hi René,

what do you mean exactly by activating?

Do you mean the active layer should change?

 

The following ExtendScript (JavaScript) code will do this:

var doc = app.documents[0];
var layerLength = doc.layers.length;

if( doc.activeLayer.index < ( layerLength - 1 ) )
{
	doc.activeLayer = doc.layers[ doc.activeLayer.index + 1 ];
};

 

You could assign a keyboard shortcut to the script after installing it to InDesign's Scripts panel.

But I don't know if ctrl + arrow down key is possible. Cannot test this. I am on Windows 10.

 

Regards,
Uwe Laubender

( ACP )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2020 Feb 22, 2020

hi uwe,

 

i'm fairly new to scripting, so maybe i've explained myself not correct.

my indesign document contains 10 layers.

layer 1 is active (i'm working in it)

then i want to deactivate this layer and continue working in the next one, layer 2.

then deactivate layer 2 and activate and work in layer 3.

then in 4, 5, 6 etc.

the deactivation of the current layer and activation of the next layer should only take place after i press a key or key combination (may be any key or combination).

i hope this clarifies a little.

rené

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2020 Feb 22, 2020

Did you try Uwe’s script with a key command assigned? It seems to do what you are asking for. On OSX Control-Down might be used by the system—Control-Option-down worked for me.

 

Here is an AppleScript version:

 

 

tell application id "com.adobe.indesign"
	tell active document
		set i to index of active layer
		if i is less than (count of layers) then
			set active layer to item 1 of every layer whose index is (i + 1)
		end if
	end tell
end tell

 

Before pressing key assignment

Screen Shot 3.pngexpand image

After

Screen Shot 4.pngexpand image

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2020 Feb 22, 2020

hi rob,

 

wonderful!

with a small adjustment (set visible of every layer to false; set visible of layer i to true) your applescript version of uwe's script does exactly what i need.

thanks to both of you.

 

rené

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2020 Feb 22, 2020

Hi René,

perhaps you want to lock all layers but the active one?

And perhaps the first layer in the stack should be the next active one if you reached the bottom of the stack?

 

var doc = app.documents[0];
var layerLength = doc.layers.length;

if( doc.activeLayer.index < ( layerLength - 1 ) )
{
	doc.activeLayer = doc.layers[ doc.activeLayer.index + 1 ];
};
else
{
	doc.activeLayer = doc.layers[0];
};

doc.layers.everyItem().locked = true;
doc.activeLayer.locked = false;

 

Regards,
Uwe Laubender

( ACP )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2020 Feb 22, 2020

hi uwe,

 

applescripts i can understand and manipulate a little bit, but javascripts are abacadabra to me, unfortunately.

your script works when i use it in indesign.

locking however is not required, but visibility is.

and your second suggestion is a good one. thanks.

 

rené

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2020 Feb 22, 2020

Hi René,

in this case it's very easy to change the code from locked to visible and from true to false.

See into document object model documentation for object Layer with ExtendScript:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layer.html

 

We can change the last two lines of my code for layer visibility like that:

doc.layers.everyItem().visible = false;
doc.activeLayer.visible = true;

 

Regards,
Uwe Laubender

( ACP )

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2020 Feb 22, 2020
LATEST

hi uwe,

 

with your latest adaptation it's just as i wished for.

thank you very much. it seems so easy...

 

rené

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines