Copy link to clipboard
Copied
Hello Everyone!
I'm trying to make a script that will clear and then reload actions to try to get around that bug. Thanks to quertyfly and moluapple I now know how to make actions through script so all I need to know if there is a way to clear actions through script.
Thanks Everyone!
Woo Hoo....
feeling a bit stupid that I had not tried this.
But it works.
You don't even need to first unload each action
to remove a set...
app.unloadAction('Test Set','');
now to activate the file menu...
Copy link to clipboard
Copied
Hey, I quite possibly take back about 50% of stuff I said on this thread, because I had done some experiments with actions and scripts last weekend and I was surprised things did not come out as I had expected. We were using CC2014, and I was trying to play an action which had a script in it, but the action was also playing an action before the script was to be played. It didn't work, complaining that the "{{script-name}} object does not exist". The same action did work when I switched the order, and made the script play first, then play the nested action. I really did not get a chance to test scripts playing actions when launched via action, but this one discrepancy makes want to not trust the actions palette even more.
Copy link to clipboard
Copied
Actions that run scripts I don't have a problem with after reload, unless the script tries to run an action with the app.doScript command, that is when Illustrator crashes and burns for me. I also notice a delay when loading or unloading or creating actions through script. For example, when I create a temporary action through a script and delete it in the end, I get a delay. My action panel will still have the ghost action there. Next time I interact with the action pallets tho, it disappears.
Copy link to clipboard
Copied
I wonder if an app.redraw(); may fix your ghost action issue.
Copy link to clipboard
Copied
I tried that, it doesn't seem to work. It's not a big deal tho, it will disappear next time I use an action.
Copy link to clipboard
Copied
an action that runs a script that runs an action?
Copy link to clipboard
Copied
its a bit like my above Javascript that deletes actions, creates a Javascript and a VBscript, runs that VBscript which in turn runs the javascript which adds actions so we can run script from actions.
you would think we all program for Microsoft...
Copy link to clipboard
Copied
you would think hahaha, maybe these days there are other giants worst than MS...well, if absolutely necessary, why not?
Copy link to clipboard
Copied
giants worse then MS, you mean like ADOBE... I never said that. no really I never said that.
Copy link to clipboard
Copied
hang on, wait... I do program for adobe, in a roundabout kinda way.
Copy link to clipboard
Copied
Yea I know it is some inception stuff haha. The reason is there are some things I still can't figure out how to do through script. That menu command thread has been very helpful to me, I have been able to cross a lot of those things off the list. One thing I still can't do though is Flatten Transparency without the dialog box popping up. I just do that through the action so I don't have to click 'ok'.
Copy link to clipboard
Copied
That is / was my #1 reason for actions via script, when CS6 first came out, is the Flatten Transparency. I had discovered that FT is one of the single best useful commands when it came to my production art, because it eliminated clear paths (something that you get when designers outline fonts and use them in a pathfinder ops, so that the hold of an "O" fills in with a clear path, which causes problems later) ,it outlined strokes, so that artists wouldn't accidentally scale strokes wrong, and of course the font-outlining and appearance-flattening. Such as when you have an arched text, but script doesn't know appearance bounds. Also, I noticed it helped with some Illustrator-internal script (MRAP, anyone?) errors from documents we'd open which came from outside the building.
Copy link to clipboard
Copied
Yea I'm in production art too so I can relate to almost everything you said haha. I also like that it gets rid of groups within groups as well so it's just one simple group with paths and compound paths, a lot easier to script. I started out with CS6 so I didn't know it was new. That must have been tough not having it lol.
Copy link to clipboard
Copied
Oh, yea! I did forget: Groups within Compound Paths! Ahh! What a nightmare, some files we got had those all over the place, and FT takes care of that weird stuff right away.
Copy link to clipboard
Copied
app.executeMenuCommand ('Flatten Transparency')
EnterKeyWindows();
function EnterKeyWindows(){
var VB = [
'Set appRef = CreateObject("Illustrator.Application")',
'Set WshShell = WScript.CreateObject("WScript.Shell")',
'WshShell.SendKeys "{ENTER}"',
'JS = "~/go.jsx"',
'appRef.DoJavaScriptFile(JS)',
].join('\n');
var VBgo = new File('~/go.vbs');
VBgo.open('w');
VBgo.write(VB);
VBgo.close();
VBgo.execute();
}
Looks like the enter key won't activate until you close out of the Flatten Transparency dialog. Darn.
Copy link to clipboard
Copied
EnterKeyWindows();
app.executeMenuCommand ('Flatten Transparency')
function EnterKeyWindows(){
var VB = [
'Set appRef = CreateObject("Illustrator.Application")',
'Set WshShell = WScript.CreateObject("WScript.Shell")',
'WshShell.SendKeys "{ENTER}"',
'JS = "~/go.jsx"',
'appRef.DoJavaScriptFile(JS)',
].join('\n');
var VBgo = new File('~/go.vbs');
VBgo.open('w');
VBgo.write(VB);
VBgo.close();
VBgo.execute();
}
Now it seems to work!! Weird I just put it before instead of after.
Copy link to clipboard
Copied
I think it may be because of how the dialog will put a pause on all script activity, when one is up.
So, you have to end up putting your Enter-key script into action before the dialog pops up and prevents the javascript from executing further. Now, in your revised version, that the JSX writes the VB before the dialog appears, the VB is already set in motion as an external process, and swoops in after the dialog is up to send the key.
Copy link to clipboard
Copied
WHat a freaking useful script. We can make a function to send a custom set of keystrokes to any app.executeMenuCommand dialog. The only thing is, I'd like to know more about the syntax of these things so that we can make sure all of the dialog settings are conditionally checked to make sure they are as desired.
Copy link to clipboard
Copied
The issue with this approach is to do with when things run.
we tend to lose control as we are now running 2 threads.
if you run the executeMenuComand then we get the script pausing till the dialog is dismissed.
so run the SendKeys function first, so it is in play before the dialog has displayed.
but if the dialog gets delayed for any reason I don't think the sendKeys will are going to wait for it to arrive.
the vb should really be testing for the window to be displayed before it starts sending the keys.
not sure if I have this correct or not.
but I think I am at least on the right track.
Copy link to clipboard
Copied
Right, and if checking is even possible, it's a coon new level of complexity to do both in mac and pc. However, if a generic function is created, it could be used to take care of many cases.
Speaking of which, I wanted to add to the "Action Re-loader" on the Mac part, but my .applescript always opens in the script editor vs running. I have worked around this before by always having an executing .app file which does run when used .execute() on, and I made it always open up a written .scpt file ( which I think is the same as .applescript) in the script editor , play it and then delete it. Looking for a smarter way which can still accept an applescript string as an argument to make it possible to run any dynamically written applescript.
Copy link to clipboard
Copied
I'm not liking the re-loader at the moment as after a crash, illustrator opens it recovered files, causing the vb to wig out.
I have not sat down and tried to nut out a way around it yet.
is the .app file compiled or is it the same as the .scpt file but with a different extension?
also, I know you can send keys with applescript. but is there a simple way of accessing the file menu with a shortcut?
I looked in to this and as far as I can tell you can access the file menu in a similar way, but only if you go in and tweak some system preferences.
I think some machines will toggle this setting with Ctrl + F1 or Ctrl + fn + F2.
and once you access the menu its not as straight forward as PC, as you have to type the first few letters of the item rather then a designated letter.
Copy link to clipboard
Copied
here was my first attempt at a dual platform send keys function.
I cant remember if I ever tested it on a mac or not...
but from what your saying, I guess it will just open for editing...
function Send_Keys(){
var platform = String(app.path).indexOf("Application") == -1?"vbs":"APPLESCRIPT";
var sendKeysScriptFile = new File('~/send_keys_script_file.' + platform);
if(sendKeysScriptFile.exists){
sendKeysScriptFile.execute();
}else{
var code;
if(platform === "vbs"){
//VB
code = [
'Set WshShell = CreateObject("WScript.Shell")',
'WshShell.SendKeys "v"'
].join('\n');
}else if(platform === "APPLESCRIPT"){
//AS
code = [
'tell application “System Events” to keystroke "v"',
'end tell'
].join('\n');
}else{alert("error detecting your platform");}
sendKeysScriptFile.open('w');
sendKeysScriptFile.write(code);
sendKeysScriptFile.close();
sendKeysScriptFile.execute();
}
}
Send_Keys();
Copy link to clipboard
Copied
this is what I have saved as a reference.
I do use it in the odd script.
I find the reference section at the top quite handy, even if it is ripped straight from MS
function JS_SendKeys(str) {
// Function by Qwertyfly.
// this will leave the go.vbs file behind, not that this should be an issue.
// https://msdn.microsoft.com/en-us/library/aa266279(v=vs.60).aspx
/*
Sends one or more keystrokes to the active window as if typed at the keyboard.
Syntax - SendKeys string[, wait]
The SendKeys statement syntax has these named arguments:
Part Description
string Required. String expression specifying the keystrokes to send.
Wait Optional. Boolean value specifying the wait mode. If False (default), control is returned to the procedure immediately after the keys are sent. If True, keystrokes must be processed before control is returned to the procedure.
Remarks
Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, use "A" for string. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, use "ABC" for string.
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses ( ) have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use {+}. Brackets ([ ]) have no special meaning to SendKeys, but you must enclose them in braces. In other applications, brackets do have a special meaning that may be significant when dynamic data exchange (DDE) occurs. To specify brace characters, use {{} and {}}.
To specify characters that aren't displayed when you press a key, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes shown below:
Key Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes:
Key Code
SHIFT +
CTRL ^
ALT %
To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".
To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.
Note You can't use SendKeys to send keystrokes to an application that is not designed to run in Microsoft Windows. Sendkeys also can't send the PRINT SCREEN key {PRTSC} to any application.
*/
var VB = [
'Set WshShell = WScript.CreateObject("WScript.Shell")',
'WshShell.SendKeys "' + str + '"',
].join('\n');
var SKF = new File('~/go.vbs');
SKF.open('w');
SKF.write(VB);
SKF.close();
SKF.execute();
}
JS_SendKeys("%(fn){enter}"); // I know this is not ever needed as can be done with JS, but it is an example.
Copy link to clipboard
Copied
Thank you for this additional knowledge. The .app is a compiled "bundle" application-thing which executes in response to .execute() from a .jsx, but you can also go on Mac and right-click to access the "contents" of the .app - which then becomes a folder directory full of stuff, and has .plist file, etc, and finally has a folder which contains a .scpt which is whatever the applescript you wrote and saved as .app. So it's got all kinds of folders and stuff and the main script it runs, with the main difference is that the .app can be .execute()d . Actually if it were possible to directly write to the .scpt inside the .app, there would be no need to write an execution function to open up an external .scpt in scipt editor and play it.
Copy link to clipboard
Copied
do you think we could get the script to create the archive?
might be a bit hard to make sure all the encoding is correct.
but what if you build an .app that can accept arguments.
there must be a way to .execute() including an argument.
then you could just add the .app to any mac that need the script.
Copy link to clipboard
Copied
Hmm, I only know that one can save a .app file by using Save As in the Script Editor, but it's a lot of junk there.. let me see my mactop about some screenshots!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now