Applescript to make an applescript?

Is this possible?

I want to make an applescript to ask a series of questions then apply the answers to an exisiting applescript. So that the main file can be updated,

The questions would be the 12 different options on one line.


Thanks


Matt


The file to update looks like this

property brandTable : {¬

	{brandID:{"AP88"}, brandGroup:{"Apricot", 1500, 1500, true, false, "FFFFFF", true, true, true, false, true}}, ¬

	{brandID:{"BA44"}, brandGroup:{"Banana", 1020, 1530, false, false, "F4F4F4", false, true, true, false, true}}, ¬

	{brandID:{"CA22", "CC24"}, brandGroup:{"Cauliflower", 1196, 1300, true, false, "FFFFFF", true, true, true, false, true}} ¬

		}

Posted on Feb 7, 2019 6:22 AM

Reply
19 replies

Feb 7, 2019 11:23 AM in response to MattJayC

While your approach may be possible with a lot, lot of work, it would be far, far easier to pass the info via a variable or in a file.


Why doesn't this approach work?

https://discussions.apple.com/thread/250121723


So, your looking to dynamically change the data. Where as before, it was static data. You could put the questions into the main script that you load into the others. running the main script would ask the questions and change the data.


You could use the two script method I mentioned. The questioning script would invoke the "static" script with the data. The static script would update it's data.


R

Feb 7, 2019 12:14 PM in response to rccharles

For the most part it is static.

but once every month or so I need to add a new line to it.

now for me this is easy and I think easily understood. But for others to use it I was hoping to make it fool proof by running a script that will prompt the questions and then complete the script.


Failing that I could just write down some instructions on how to complete!


So, it is actually possible to write to an AppleScript? what would that basic method be? Or am I right in thinking I need another text editor to do it?

Feb 8, 2019 1:51 AM in response to rccharles

So I have currently gone with a script called properties.scpt and all other scripts point to this one! Works well.


I have another script someone helped me with that is in photoshop script, this runs in photoshops events manager.

The way that works is when I press C in photoshop for the crop tool, it interupts it, looks at the filename and then from the name looks it up and selects the ratio it needs to be. This is the same information contained in the properties file.


Like from the other thread I am trying to minimise having to updated every script everytime something new comes along. At least at the moment its down to two. Whereas before I was updated 7 everytime!!



Feb 14, 2019 1:21 AM in response to rccharles

From Photoshop I use the Scripts Event Manager. See the link here. This is my original post, now I used to press C in photoshop for the croptool to be selected. Script Events manager then interrupt it and ran a bit of javascript.


This Javascript I have here I now run in from within Applescript.


The only Javascript I have that the Scripts event manager calls for is this one line.


app.system("open '/path/to/script_as_an_app.app'");


The applescript is saved as an App and looks like this.


Hopefully you can see that I collect the Ratio with applescript as mainRatio and then pass it to the javascript.

At the moment this seams to work quite well. Its not quite as quick as using only javascript. So I have to slow down by about half a second for it to catch up.


Otherwise it works well.









Feb 14, 2019 1:22 AM in response to MattJayC

set brandNames to ""
set brandIDs to {}
set brandNamesList to ""
set DCKProperties to load script file "path:to:app:Properties.scpt"
set brandTable to DCKProperties's brandTable

repeat with x in brandTable
	repeat with y in (x's brandID's items)
		copy y as text to end of brandIDs	
	end repeat	
end repeat
tell application id "com.adobe.photoshop"
	activate
	set textName to name of current document
end tell
set the1stLetter to textName's character 1
set brandID to textName's text 1 thru 4


if brandID is not in brandIDs then
	tell application id "com.adobe.photoshop
		set brandNames to instructions of info of current document
	end tell
if brandNames is equal to "" or brandID is in EAN_Inclusion then
		tell application "System Events"
			activate
			set brandNames to choose from list my get_brandNames(brandTable) with prompt "Choose brands to send out." default items {"Freedom"}
			end tell
		if brandNames = false then
			tell application id "com.adobe.photoshop" to activate
		end if
	end if
	set brandGroup to my get_brandGroup(brandTable, brandNames, missing value)
else
	set brandGroup to my get_brandGroup(brandTable, brandNames, brandID)
end if
try
	set XWidth to 2nd item of my get_brandGroup(brandTable, missing value, brandID)
	set YHeight to 3rd item of my get_brandGroup(brandTable, missing value, brandID)
on error
	
	set XWidth to 2nd item of my get_brandGroup(brandTable, brandNames, missing value)
	set YHeight to 3rd item of my get_brandGroup(brandTable, brandNames, missing value)
end try
set mainRatio to (XWidth / YHeight)

Feb 14, 2019 1:24 AM in response to MattJayC

tell application id "com.adobe.photoshop"



tell current document


do javascript "// 2016, use it at your own risk;


#target photoshop


/*var ref = new ActionReference();


ref.putEnumerated( charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );


var applicationDesc = executeActionGet(ref);


var currentToolOpt = applicationDesc.getObjectValue(stringIDToTypeID('currentToolOptions'));


var settings = currentToolOpt.getObjectValue(currentToolOpt.getKey(0));


var defaultwidth (settings.getUnitDoubleValue(settings.getKey(3)));


var defaultheight (settings.getUnitDoubleValue(settings.getKey(5)));*/




if (app.documents.length > 0) {


var myDocument = app.activeDocument;


var originalRulerUnits = app.preferences.rulerUnits;


app.preferences.rulerUnits = Units.PIXELS;


var width = myDocument.width;


var height = myDocument.height;


var rel = " & mainRatio & ";






// =======================================================


var idslct = charIDToTypeID( 'slct' );


    var desc5 = new ActionDescriptor();


        var ref2 = new ActionReference();


        ref2.putClass( stringIDToTypeID( 'cropTool' ) );


    desc5.putReference( charIDToTypeID( 'null' ), ref2 );


    desc5.putBoolean( stringIDToTypeID( 'dontRecord' ), true );


   desc5.putBoolean( stringIDToTypeID( 'forceNotify' ), true );


executeAction( idslct, desc5, DialogModes.NO );


try {


// =======================================================


var idCrop = charIDToTypeID( 'Crop' );


    var desc3 = new ActionDescriptor();


    var idT = charIDToTypeID( 'T   ' );


        var desc4 = new ActionDescriptor();


        var idTop = charIDToTypeID( 'Top ' );


        var idPxl = charIDToTypeID( '#Pxl' );


        desc4.putUnitDouble( idTop, idPxl, 0 );


        var idLeft = charIDToTypeID( 'Left' );


        var idPxl = charIDToTypeID( '#Pxl' );


        desc4.putUnitDouble( idLeft, idPxl, (width - height * rel) / 2 );


        var idBtom = charIDToTypeID( 'Btom' );


        var idPxl = charIDToTypeID( '#Pxl' );


        desc4.putUnitDouble( idBtom, idPxl, height );


        var idRght = charIDToTypeID( 'Rght' );


        var idPxl = charIDToTypeID( '#Pxl' );


        desc4.putUnitDouble( idRght, idPxl, (width - height * rel) / 2 + height * rel );


    var idRctn = charIDToTypeID( 'Rctn' );


    desc3.putObject( idT, idRctn, desc4 );


    var idAngl = charIDToTypeID( 'Angl' );


    var idAng = charIDToTypeID( '#Ang' );


    desc3.putUnitDouble( idAngl, idAng, 0.000000 );


    var idDlt = charIDToTypeID( 'Dlt ' );


    desc3.putBoolean( idDlt, false );


    var idcropAspectRatioModeKey = stringIDToTypeID( 'cropAspectRatioModeKey' );


    var idcropAspectRatioModeClass = stringIDToTypeID( 'cropAspectRatioModeClass' );


    var idpureAspectRatio = stringIDToTypeID( 'pureAspectRatio' );


    desc3.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idpureAspectRatio );


    var idCnsP = charIDToTypeID( 'CnsP' );


    desc3.putBoolean( idCnsP, true );


executeAction( idCrop, desc3, DialogModes.ALL );


} catch (e) {};


//


app.preferences.rulerUnits = originalRulerUnits;


};"



end tell


end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript to make an applescript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.