Copy link to clipboard
Copied
Working with a third part extension that always creates new doc's as points.
I was thinking of startup script that "after new" would:
set horizontal measurement units to inches
set vertical measurement units to inches
but i am not sure how to write it??
below is a script another person created but if i read it correctly it "views" the prefs?? maybe i am misunderstanding the use of "view"
tell application "Adobe InDesign 2023"
tell view preferences
set ruler origin to page origin
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
end tell
i thought possibly i would write
tell application "Adobe InDesign 2023"
set myEventName to {"afterNew"}
repeat with myEventName
make event listener with properties {event type:myEventName, handler:"?"}
end repeat
end tell
its been awhile since i did any scripting. any ideas??
Copy link to clipboard
Copied
Hi,
The first code block should work, the actual object you are changing is called "view preferences".
So that code is setting the values inside the "view preferences" object
Copy link to clipboard
Copied
there must be a better way to write this. i created a start up script with the handler as path to the the first script isaved into my scripts panel
tell application "Adobe InDesign 2023"
set myEventNames to {"afterNew"}
repeat with myEventName in myEventNames
make event listener with properties {event type:myEventName, handler:"Macintosh HD:Applications:Adobe InDesign 2023:Scripts:Scripts Panel:Samples:AppleScript:name.scpt"}
end repeat
end tell
Copy link to clipboard
Copied
Hi @rickg76305781 , Try this Javascript.
#targetengine "session"
app.eventListeners.add("afterNew", setRulers);
function setRulers(e){
var d = e.parent;
d.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.INCHES, verticalMeasurementUnits:MeasurementUnits.INCHES}
}
The AppleScript equivalent should be this where the evt variable references the event—the handler reference can’t have a parameter—but the evt reference is throwing an error:
tell application id "com.adobe.indesign"
--tell event listeners to delete
make event listener with properties {event type:"afterNew", handler:my setRulers}
end tell
on setRulers()
tell application id "com.adobe.indesign"
set d to parent of evt
set properties of view preferences of d to {horizontal measurement units:points, vertical measurement units:inches}
end tell
end setRulers
Copy link to clipboard
Copied
I had some time to test and the first script does work and adding an event listener to the workflow does change the scale to inches afternew. BUT thats not the result I was expecting
The script changes the prefs to inches after doc creation. BUT it doesnt change the units of the doc that was created. All docs creeted after the first doc would be in inches.
.
What i would like to happen is: afterNEW, change scale of the current doc to inches.
I think i need to modify the first script (below) to change the scale of the current doc. Not sure how to make that happen. I am sure its a simple.
tell application "Adobe InDesign 2023"
tell view preferences
set ruler origin to page origin
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
end tell
Copy link to clipboard
Copied
The view preferences can be a property of the application or a document—your AS is setting the application’s view preferences not the active document. This would set the InDesign default to points and the active document to inches:
tell application id "com.adobe.indesign"
--sets the application’s view preferences
set properties of view preferences to {horizontal measurement units:points, vertical measurement units:points, ruler origin:page origin}
--sets the active document’s view preferences
set properties of view preferences of active document to {horizontal measurement units:inches, vertical measurement units:inches, ruler origin:page origin}
end tell
JS:
//sets the application
app.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.INCHES, verticalMeasurementUnits:MeasurementUnits.INCHES}
//sets the document
app.activeDocument.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.INCHES, verticalMeasurementUnits:MeasurementUnits.INCHES}
Running with a document open preferences shows Inches:
With no documents open Preferences shows Points:
In order to get the document that is created from the afterNew event you have to get the event’s parent. So this throws an error when I create a new doc and click OK with no docs open:
#targetengine "session"
app.eventListeners.add("afterNew", setRulers);
function setRulers(e){
//the new document is not available yet
var d = app.activeDocument;
d.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.INCHES, verticalMeasurementUnits:MeasurementUnits.INCHES}
}
But this works because the new document is the parent of the event:
#targetengine "session"
app.eventListeners.add("afterNew", setRulers);
function setRulers(e){
var d = e.parent;
alert("New Document named " + d.name + " has been created")
//set the new document’s view prefs
d.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.INCHES, verticalMeasurementUnits:MeasurementUnits.INCHES}
}
Copy link to clipboard
Copied
i havent had much time to test but i used my existing event listener and run jsx
var d = app.documents
for (var i = 0; i < d.length; i++){
d[i].viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;
d[i].viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;
};
app.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;
app.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;
Copy link to clipboard
Copied
any time a new doc is created it makes the unit meansure of the new doc into inches
Copy link to clipboard
Copied
any time a new doc is created it makes the unit meansure of the new doc into inches
That would be expected if you are listening for the afterNew event and setting the new doc to inches from its handler. If you remove the listener new documents would use the application’s preference.
Copy link to clipboard
Copied
Not sure why the evt variable wasn’t working for me yeserday, but just tested it out of the Scripts panel and this works. Note that I’m setting the document’s, not the application’s, view prefs
tell application id "com.adobe.indesign"
make event listener with properties {event type:"afterNew", handler:my setRulers}
end tell
on setRulers()
tell application id "com.adobe.indesign"
set d to parent of evt
set properties of view preferences of d to {horizontal measurement units:inches, vertical measurement units:inches, ruler origin:page origin}
end tell
end setRulers