Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hey there,
i have to bump this thread again out of oblivion:
Was anyone able to house this script in startup stripts with an event-handler after open? I read several threads about APID, afterOpen and var myDoc = app.documents[0]; but i'm not able to get it done, due lack of JS-skills.
Has anyone done this/can provide a clue to achieving this?
Here is what didn't worked so far:
#target indesign
#targetengine "session"
main();
function main()
{
var myEventListener = app.eventListeners.add("afterOpen", ReziseWindow, false);
}
function ReziseWindow()
{
var myDoc = app.documents[0];
myPath = app.activeScript;
myParts = myPath.toString().split("/");
myParts[(myParts.length - 1)] = "WindowDefault" + app.version.slice(0,1) + ".txt";
myNewPath = myParts.join("/");
mySettingsFile = File(myNewPath);
if (app.windows.length < 1) {
beep();
if (confirm("Kein Fenster geöffnet; Soll die Einstellungsdatei gelöscht werden?")) {
if(mySettingsFile.exists) {
mySettingsFile.remove();
}
}
} else {
if (mySettingsFile.open("r")) {
savedBounds = mySettingsFile.read();
mySettingsFile.close();
myBounds = savedBounds.split(",");
for (i = 0; i<myBounds.length; i++) {
myBounds = Number(myBounds);
}
app.windows[0].bounds = myBounds;
} else {
beep();
if (confirm("Einstellungsdatei nicht vorhanden; Aktives Fenster nutzen um Position zu speichern?")) {
new File(mySettingsFile);
mySettingsFile.open("w");
mySettingsFile.write(app.windows[0].bounds);
mySettingsFile.close();
}
}
}
}
Copy link to clipboard
Copied
I think Startup is too early for this script to do anything. There's no window for it to operate on at that point.
You might be able to make it responsive to an onOpen event, although even that might be too early because the window comes after the event.
I've never felt the urge to do this kind of thing because I actually use a pair of instances of this script each with a shortcut to toggle between full and half screen. I even have another instance that will push the document on to my second monitor, so having any of them operate automatically is of marginal value.
Dave
Copy link to clipboard
Copied
I thought scripts that listen to any handlers should be start up scripts. As you see
var myEventListener = app.eventListeners.add("afterOpen", ReziseWindow, false); the script should only run if any document is opened.
I thought about your idea of having multiple variations of the script, but i only need one window-position to fit my workspace near my pallettes, so it should be applied to any opened window after open.
But, curse me for not having any skills in JS, i cant get it to work.
Copy link to clipboard
Copied
I've written so few event-handling scripts that I'm not much use here, but I suspect that your problem could well be that afterOpen happens after the document opens but before the window is drawn.
Dave
Copy link to clipboard
Copied
I don't really know where I read this today, but I did some research today on topics regarding the "afterOpen"-handler not working before CS4 and fireing befor the window is drawn. Kasyan often suggested to use an eventhandler from APIDToolAssistant and provided a script for this (RememberDocumentsPosition.spln), but somehow it doesnt work.
In a later thread he acknowledge that the InD-handler isnt broke, but has to be used with var myDoc = app.documents[0];
But since I can script java, i dont know where to house this in your given script (which, to give you kudos here, is great the way it is)
Copy link to clipboard
Copied
Thanks for the compliment.
re: var myDoc = app.documents[0];
The first statement of the ResizeWindow function is precisely that.
I'll try some experiments to see if I can get a handle on this, but don't hold your breath!
Dave
Copy link to clipboard
Copied
I started a new topic which you may have seen, but just in case, this seems to work (I was wrong about there not being a window to work with):
#target indesign
#targetengine 'dave'
(function(){
var myEventListener = app.eventListeners.add("afterOpen", testFunction, false);
function testFunction() {
app.layoutWindows[0].bounds = [50, 32, 1143, 944];
}
}())
Dave