[JS] [CS5.5] interrupt a script via ScriptUI

I have a script that automates the placement of PDF files in pages based on an input XML file. It works fine, but I want users to be able to interrupt the establishment, especially if they have accidentally passed the bad XML file to the script!

The total time required for the investments of PDF may take a while, I put a window simple palette containing a progress bar to give an idea of the progress. I also added a Cancel button, but although the window seems to have developed at least from time to time during the internship, it is never possible to press the Cancel button, or close the window. The mouse pointer is an hourglass all the time.

This is a test script simplified illustrating the problem. I have only run on CS5.5 on Windows XP, but I think it should work at least as far as CS4 on Mac and Windows. He asked a PDF file and then placed in a new document 16 times. My PC is slow enough so that it takes enough time together to give me enough time to hit the Cancel button, if it was possible to do. If your machine is really fast, you might want to increase gridSize so that the script has more to do.

Is that what I do as my Undo button can be pressed? I need to import PDF window, so if this can and should be turned off, that's fine. I've tinkered with IdleTasks strings and was able to push my button to cancel, but the chain is not always end, and I ended up locking things badly. I probably need to read more about IdleTasks. There may be potential here, but I want to support prior to version CS5 if possible, and IdleTasks were introduced in CS5.

#target indesign

(function() {
    var gridSize = 4;

    // Ask user for a PDF
    var pdfFilter =($.os.toLowerCase().indexOf("macintosh") != -1) ?
        (function(file) { return file.name.match(/\.pdf$/); }) : '*.pdf';
    var pdfFile = File.openDialog("Choose a small PDF to place...", pdfFilter);
    if (!pdfFile) { return; }

    // Show a simple progress bar
    var active = true;
    var win = new Window('palette', 'Placing ' + pdfFile.name);
    var label = win.add('statictext', undefined, '');
    label.preferredSize.width = 300;
    label.justify = 'left';
    var progressBar = win.add('progressbar', undefined, 0, gridSize * gridSize);
    progressBar.preferredSize = [ 300, 12 ];
    var cancelButton = win.add('button', undefined, 'Cancel');
    cancelButton.onClick = function() { win.close(); };
    win.onClose = function() { active = false; };
    win.show();

    // Make a grid of rectangles and place the PDF in each rectangle,
    // advancing the progress bar as we go
    var doc = app.documents.add();
    var page = doc.pages[0];
    var mp = page.marginPreferences;
    var originX = page.bounds[1] + mp.left;
    var originY = page.bounds[0] + mp.top;
    var rectWidth = (page.bounds[3] - mp.right - originX) / gridSize;
    var rectDepth = (page.bounds[2] - mp.bottom - originY) / gridSize;
    var placePDF = function(n) {
        var y = Math.floor(n / gridSize);
        var x = n % gridSize;
        label.text = 'Placing PDF in [ ' + x + ', ' + y + ' ]';
        var rect = page.rectangles.add();
        rect.geometricBounds = [
            originY + y * rectDepth,
            originX + x * rectWidth,
            originY + (y + 1) * rectDepth,
            originX + (x + 1) * rectWidth
        ];
        rect.strokeWeight = 0;
        var pdfList = rect.place(pdfFile);
        pdfList[0].fit(FitOptions.PROPORTIONALLY);
        (progressBar.value)++;
        // Even this sleep doesn't let me press the cancel button!
        //$.sleep(1000);
    }
    for (var i = 0; active && i < gridSize*gridSize; i++) {
        placePDF(i);
    }
    win.close();
})();

Hi all

To my knowledge ScriptUI can only process "update" events during execution of your heavy routine. As a solution Roey horns of Adobe suggested in the past that we "rely on the support of InDesign to cancel scripts using the Cmd-period or ESC key".

In any case, IdleTasks is definitely the way to go in CS5 and later.

@+

Marc

Tags: InDesign

Similar Questions

  • Marked 2 scripts via TextWrangler

    I want to script this workflow:

    • Create a new document of TextWrangler that contains text (Markdown) currently in the Clipboard
    • Save the doc with a name unique (for example date/time) on the desktop
    • Perform the search and replace to grep next: replace "(\\ [|)" (\\]) ' using '\\\1' to search in the text 1 the options of the text document 1 {search:grep, starting at top:true}
    • Save the document
    • Open the document in marked 2
    • Trigger a hotkey (command-option-control-X) for export as docx
    • Save the export on the desktop

    Checked 2 is scriptable, so there should be a way to transmit this document directly from TextWrangler to marked 2, maybe even without having to save it (which would be better).

    Here's where I am so far:

    Set myText to the Clipboard

    Tell application "TextWrangler.

    activate

    Tell application "system events".

    Press the 'v' command {down}

    tell the end

    Tell application "TextWrangler.

    activate

    replace "(\\ [|)" (\\]) ' using '\\\1' to search in the text 1, document 1 of the text options {search mode: grep, starting at the top: true}

    tell the end

    I have simplified your script a little and added what looks like it should do what you want, even if I get an error that my document cannot be exported as docx - I don't know if it's because I'm the appellant badly (documentation markup 2 fails in this area), or if there is something on the text I save. Try on a real example and see what happens.

    Worst case you can be able to compel UI Scripting by selecting the appropriate export-> as DOCX menu item (or talk to the author of how to export via AppleScript).

    the value of myText to the Clipboard

    the value shell script filename ' date '+ % Y.%m.%d '"

    the value filePath to ((path to the Office as text) & filename & ".txt") as text

    say application 'TextWrangler.

    the value newDoc to make new text document with properties {text: myText}

    replace « (\\ [| (\\]) ' using '\\\1' to the search in the options of text 1 of newDoc {search:grep, starting at top:true}

    newDoc Save to the file filePath

    the value f for file of document to window 1 as alias

    end say

    say application "Scored 2.

    f Open

    Save front document in the file ((path to the Office as text) & file & ".docx")

    end say


    You could avoid the TextWrangler part, but you have to find a different way to treat your regex - which probably means that sed in a shell script, is probably just as easy to keep in TextWrangler.

  • Photoshop Remote scripting via SSH

    I'm trying to get AppleScript scripts to run on a remote server by SSH (using the osascript command line utility). However, whenever I try to do nothing more, I get various Photoshop and/or AppleScript errors that I never get when you try to run the scripts from same exact locally. At the end of the day, I'm trying to run a JavaScript JSON of Applescript arguments passing, called by SSH file. Please forgive the verbosity introduced by the simple initial example.

    Server: OS X 10.8.5

    Photoshop: CC 2014

    I see the same type of errors that I have SSH into a server and do the following manually into a shell after logon, or a ssh command to directly run the power supply (e.g., ssh user@host "osascript /path/to/script.scpt"). From a basic example, I tried to launch the following AppleScript snippet. I tried to enter in osascript handmade via stdin, as writing to a file and call it remotely. Both resulted in no new files being created, but a success message.

    Tell application "Adobe Photoshop CC 2014"

    make new document

    tell the end

    No matter how I try to execute it remotely, I get the 'untitled document' response to osascript, and Photoshop displays a dialog error: "Could not complete your request because of a program error."

    More specific to what I'm trying to do, I have the following code:

    Tell application "Adobe Photoshop CC 2014"

    time-out of 30 seconds

    do javascript("/path/to/local/file.js") with arguments ({"{\"json\"": \"document\",...}) »})

    end time-out

    tell the end

    When I try to run it locally, I never have a problem. But when I run ssh (again, either from the command line or when placing order directly to ssh), I always get the following:

    script error: expected end of the line but found identifier. (- 2741)

    In addition to osascript stop with this error, Photoshop also appears the same dialog error: "Could not complete your request because of a program error."

    Anyone has any suggestions or ideas regarding how I can get all this work?

    Thank you

    Brian

    I was able to work around this limitation by using a daemon on the local host. However, it would be nice if I could finish with this piece of code server...

    Thank you

    Brian

  • Is it possible to use the'M 'selection' in the script and scriptUI?

    I was wondering is there a way to use these selection sets that are in the script, select Menu?

    SelectionSet.png

    Using this list in ScriptUI where I can select them. It would help me to use the selection while I'm in the 'dialogue' type list Does anyone have the solution?

    SelectionSet_Browse.png

    Yay! BridgeTalk isn't the most simpler cases and best documented, but there are good examples. Thank you guys to keep me on the right track

    After that a few tries, I got some message by BT and always with type palette window! Now this opens up totally new possibilities

    #target illustrator
    #targetengine main
    
    var script_name = "BridgeTalk Test"
    var doc = app.activeDocument;
    var doc_selection = doc.selection;
    
    function btMsg() {
    
        var bt = new BridgeTalk;
        bt.target = "illustrator";
        var message = objInfo + '\r objInfo(doc_selection);';
        bt.body = message;
        bt.send();
    
    }
    
    function objInfo() {
    
        var doc = app.activeDocument;
        var doc_selection = doc.selection;
    
        for ( i = 0; i < doc_selection.length; i++ ) {
            $.writeln ([i] + " Hello BridgeTalk!");
        }
    
    }
    
    startGUI();
    function startGUI() {
    
        // Create Main Window
        var win = new Window( "palette", script_name);
    
        // Style Option for main Window
        win.orientation = "column";
        win.alignChildren = ["fill", "fill"];
    
        // PANEL: Objects Group
        var objGrp = win.add("panel", undefined, "Objects");
        objGrp.orientation = "row";
        objGrp.alignChildren = ["fill", "fill"];
    
        // BTN: Object Info
        var btnObjInfo = objGrp.add('button', undefined, "Selected Objects");
        btnObjInfo.onClick = function () {
            btMsg();
        };
    
        // Close button
        win.quitBtn = win.add("button", undefined, "Close");
    
        // Event listener for the quit button
        win.quitBtn.onClick = function() {
            win.close();
        } 
    
        // Centering & Show Window
        win.center();
        win.show();
    
    }
    
  • Projector is "full screen" look a Cs5.5 Flash action script

    How can I set up a projector for "Full screen" display Flash Cs5.5

    Knowing he already has action script.

    I tried to add FSCommands on top, nothing helps.

    stage.displayState = "fullScreen";

  • How to run a Powershell script via a batch file

    I'm new on using Powershell and I have a fundamental question regarding running a powershell script. Basically, I wrote a file of commands as shown below.

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe - PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" - NoExit-command "C:\MyScripts\RunSpanshot.ps1".

    I run the batch file and nothing seems to happen. What is the problem with trying to run the RunSpanshot.ps1 script as shown above? -any help is appreciated.

    Thank you

    You could do

    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -NoExit -Command "& 'C:\My Scripts\RunSpanshot.ps1'"
    
  • When you run the script via VMware tools when power changed, some commands in script (as a copy) has failed.

    I came across a very strange question. I tried to create some custom vmware scripting tools, such as a new .bat file. This file contains a large number of orders, mostly as copy command "copy file://\\192.168.172.5\abc.exe c:\. ». I set this file as a custom script for Script event - power on guest operating system. Everything goes well with the bat file when I tested it. But after that I changed the State of power to power on, all other commands work fine except the copy commands in the bat file. Why? How can I make it work? Of course the problem of network. And that makes me very confused.

    Hello

    First copy the files on local disk was OK.

    If this works for local disk, but not to a network drive, then hit you indeed a permissions issue any.

    But if I run the script with tools VMware service script, the commands of copy (of the remote shared folder) failed while other controls worked well. I'm quite confused.

    In fact, it is easily explained. The VMware tools service (Yes, it's a service) runs under the account Local system and by default, the local system account has no access to the network for security reasons. You can change the user of the service runs under and see if that solves your problem (very likely)

    To do this, go to computer management (right-click icon desktop, select 'Manage') and open Services and Applications, service page, locate the VMware Tools service in the list. Select properties, log on to the page tabs and change account at your own Local System account. Restart the service and it should work.

    --

    Wil

    _____________________________________________________

    Visit the new VMware developers at http://www.vi-toolkit.com wiki

  • Audition 2.0 current Batch Script interrupted, do not save completed

    I'm trying prun a script on a few hundred mp3 files to increase the volume.  It's here

    Collection: normal120-economy
    Title: Untitled
    Description:
    Mode: 4
    Cancel: 1

    Selected: 0 to 6197758 scale 6197758 SR 44100
    FREQ: Off
    cmd: channels

    Selected: 0 to 6840575 scale 6197758 SR 44100
    FREQ: Off
    Comment: Amplitude\Normalize (process)
    cmd: {7EC45406-CFB6-4C54-99B9-84CE080C1914}
    1: 1
    2: 0
    3: 0
    4: 1.2
    5: 0

    FREQ: Off
    At the end:

    However, after a single file, it stops with error "Interrupted Batch Script, current save not completed" do I need to add a pause before the next file? (how) or any idea what causes the error?  Please, I have 3 000 files to do to and individually he kills me!

    To start the line

    Selected: 0 to 6840575 scale 6197758 SR 44100

    is not a very good idea, because you try to select beyond the end of the file on which you operate. If you select 6197758 in the scale of 0 to 6197785 SR 44100, then you will select the entire file. But then again, if you have selected 0 to 1 scale 1 SR44100 you reach exactly the same thing.

    If you are using this as a part of a batch file and backups do not work properly, you'll probably need to check all the parameters of format in the treatment by lots - but try to fix the script so that it seem weird first.

  • Deployment of the OMB via the TCL script

    I need to deploy all of the mappings in a module in a new target database. I want the configuration settings for
    (1) default operating mode = "DΘfinir base" and for
    (2) default audit level = 'NONE '.
    on all maps.

    It seems that the default repository for these parameters (and I can't find where these default values can be managed) are
    (1) default operating mode = "Line in function from set failover" and
    (2) level of auditing by default = "ERROR DETAILS" on all the mappings.
    While when I deploy via the script all mappings have these settings (which we do not want) as it appears that OMB orders use these repository/user settings. Card via interface OWB deployment allows you to change the settings of configuration as requires it, but it's the long answer.

    These configuration settings can be overridden in the TCL script via OMBDEPLOY or OMBALTER or any other command OMB parameter so all mappings are deployed/configured as
    (1) default operating mode = "DΘfinir base" and for
    (2) level of auditing by default = 'NONE' on all the mappings.

    Thank you
    Dave.

    Hi Dave

    Yes, you can set the code generation and the non-use of the properties of mode from a script...
    OMBALTER MAPPING "$map" DEFINED the VALUES of PROPERTIES (GENERATION_MODE, DEFAULT_OPERATING_MODE) ("SET_BASED", "SET_BASED")

    So that you can loop around all the cards and do these things, there are also a few experts on the Exchange utility, allowing you to block of updates quickly
    http://www.Oracle.com/technology/products/warehouse/htdocs/experts/multi_config.zip

    The model is available from scripts, for example to a PLSQL mapping batch you can query the properties as follows:
    OMBDESCRIBE CLASS_DEFINITION 'BATCH_MAPPING' GET PROPERTY_DEFINITIONS

    See you soon
    David

  • When I run my script from a shortcut ExtendScript is invoked, but this isn't when I run the menu

    I use Photshop CS2 on Win XP

    I set up a keyboard shortcut (Ctrl + Alt + P) to execute a .jsx file in the folder... \Presets\Scripts\.

    When I activate the script via the keyboard shortcut ExtendScript is called and interrupts execution on main() statement (see below).

    When I activate the script via the menu file/Scripts that extendscript is not called and the script runs up to the end.

    The .jsx file is a wrapper for a .vbs script that does the 'real' work

    The .jsx is:-

    main() function
    {
    var VBSscript = file ("C:/Program Files/Adobe/Adobe Photoshop CS2/Presets/Scripts/GGN_PS_Code_v1_2.vbs");
    If (VBSscript.Exists) VBSscript.execute ();
    }
    main();

    Anyone have any ideas on how to disable the invocation of ExtendScript when I run the script from the skortcut?

    One thing to check is that the .jsx extension is associated with Photoshop and not ExtendScript.

  • Bad performance of the Script when it is called from another Script

    Hello

    I have developed a. SOUTH who calls another script via "ScriptInclude" command and I noticed a substantial decrease in performance when running in this way.

    Normally my calculation scripts runs in less then 10 sec when it is running alone.

    However, when I call the script of my. Script SOUTH it takes 2-10 minutes on the same set of data.

    It's almost as if he is running in debug mode, where I can see my channel list being filled with data that the script runs.

    What could slow this process down so much?

    With the help of DIAdem 2015 32 bit.

    OK, I used this to speed up the result and it works like a charm

    Call UIAutoRefreshSet (False)     

  • give the user local administrator rights using local admin script

    I would like to give a domain user with local administrator rights using scripts via sccm, now that user does not disconnect, and if the admin rights come into force. I want to get the user who is logged on rights and it shall take effect as it is connected. This is possible thanks to a script or restart a service or group policy update?

    Thank you very much for your time.

    Asher

    Hey Asher,

    Thanks for posting in the Microsoft Community.

    As you try to give a domain user with local administrator rights using scripts via SCCM, the question you posted would be better suited for COMPUTING public Pro on TechNet. I would recommend posting your query in the TechNet Forums to get help:

    System Center Configuration Manager

  • SNMP Trap to order Action Script in Foglight rule

    Hello everyone,

    I need to make a rule that runs a script via the Action control when a SNMP Trap has arrived. I create this?

    The script is required for integration with my SMS server.

    Best regards

    There is a similar example in our documentation, see if that helps

    http://eDOCS.quest.com/Foglight/5611/doc/cartridge-integration/IntegrationCartridge/UnderstandingWorkflow.5.php#404739

    Golan

  • Deployment script on multiple computers

    What about a Javascript on several computers

    Please bare with me, I'm new D:

    I made a script to speed up my workflow, and now she is adopted by the entire team. It's because

    each user has specific variables values, whenever I need to correct or update anything on this subject, I must change individually

    things like username (for local files) and so on.

    I was wondering if there was a way to pass values to the java-script via the shortcut as you would with some programs.

    (adding-(argument) under General properties shortcut in windows)

    This way I can just have 1 script on the server and that all run the same script,

    and pass their own arguments, rather than everyone running their own version.

    In addition, if there is another way to achieve the same goal, would be thank you so much for your suggestions


    Thank you!

    All startup scripts are read at startup, in an undefined order. All global variables defined at a higher level will be usable in all functions (but you can't use them at the highest level in other scripts, because the order is not defined).

    Be sure you are not putting your var statements in any kind of function. Your question suggests you are equating 'script' with 'function', given that you can't actually "run" a script at all, Acrobat does this at startup.

  • Special characters could not load DB via SQL * MORE

    Hi, I have a pl as .accidentally sets sql script which will insert data in database. The question is there are some records are missing and these missing records contains a special character: Sansao and Strasse. The strange was if I run the script via F5 (Toad), all data can be inserted successfully but run through SQL * MORE (Toad), all records that contain special characters are not inserted.

    Anyone here know why it didn't load these special characters via SQL * MORE?

    Probably because you have given unicode (multi byte charsets) you read with a customer of standard single-byte character set.

    It's SILLY to loading data using SQL * more. It's the wrong tool used for loading the data. It does not support the bind variable. It doesn't support liaison in bulk. It does not support direct path inserts. It is not SQL * Loader.

Maybe you are looking for