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

I have a script that automates the placement of PDFs onto pages based on an input XML file. It works splendidly, but I would like users to be able to interrupt the placement, particularly if they have accidentally passed the wrong XML file to the script!
Since the total time taken for the PDF placements can be a while, I put up a simple palette window containing a progress bar to give an idea of progress. I also added a cancel button, but although the window appears to have focus at least some of the time during the placements, it never becomes possible to press the cancel button, nor to close the window. The mouse pointer is an hourglass the whole time.
Below is a simplified test script that demonstrates the problem. I've only run it on CS5.5 on Windows XP, but I believe it should work at least as far back as CS4 on Mac and Windows. It asks for a PDF file and then places it in a new document 16 times. My PC is slow enough that it takes enough time overall to give me plenty of time to hit the cancel button, if it were possible to do so. If your machine is really fast, you might want to increase gridSize so that the script has more to do.
Is there anything I can do such that my cancel button can be pressed? I don't need to see the PDF import window, so if that can and needs to be turned off, that's fine. I dabbled with chains of IdleTasks, and was able to press my cancel button, but the chain didn't always end, and I ended up locking things up nastily. I probably need to read up more on IdleTasks. There may be potential there, but I would like to support earlier than 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();

Sadly, neither of your suggestions in reply 1 appear to make any difference.
Out of interest though, how would I additionally test that the button had been clicked if the Window held the event listener, rather than the button?
In regards to reply 2, an extra alert does not show itself either. If the onClick was being acted upon, my window would close. It is only when the window closes that the "active" boolean is set to false to terminate the placement loop, but my window remains open no matter how often I click.
I think the trouble is really that I'm expecting multi-threaded behaviour (one thread for the placement loop, one to look after the gui and process clicks) when in reality there is only one thread, and it's busy placing PDFs. I wonder though if there is some pseudo-way to carve up the single thread and get it to check GUI state often enough to get what I want. As I said earlier, using IdleTasks sort of works in principle, but can get a little out of control!

Similar Messages

  • Execute photoshop script via illustrator cs5

    Hi
    Is it possible to execute Photoshop script via illustrator
    I have 2 different script
    script 1 work in illustrator with eps file and export as jpeg
    script 2 where i want to trim the exported jpeg for illustrator in photoshop and save it back
    I have 2 differnt script with me
    can anyone help me to club both and run at same time..
    Thank you
    Appu

    use BridgeTalk to have Illustrator talk to Photoshop, here's a sample by Mark
    Illustrator script to open file in Photoshop
    or use inter app communication
    open PS, open a document
    // start your illustrator script
    var Aidoc = app.activeDocument;
    continue with your script
    // when ready, call your photoshop script
    // this sample alerts the active document name and closes it
    photoshop.executeScript("alert('document name: ' + app.activeDocument.name); app.activeDocument.close()");

  • How to call a shell script via ODI

    Hi,
    I need suggestion on following issues:
    1) How to call a shell script via ODI?.. I tried using OSCommand utility .inspite of the execution being successful the data is not written into the new file in the desired format. After processing new file is created in the mentioned location but its empty.
    2) I'm calling a procedure in ODI to load data into my fact. But once the fact gets loaded i want to update the log details (num of rows processed,num of rows inserted,num of rows rejected etc) in my log table. I'm planning to use a proc for updating but need to know from where can i find these details. Is there a table in work rep which gives me these info like how we get if we execute an interface.?
    Please help me out.. Its urgent
    Regards
    Surabhi

    Hello,
    Question 1 appears a little vague, please elaborate. If you're looking to capture a return value from the command execution, you will need to pipe the return value to a file, then read from there.
    The execution information is stored in the SNP_STEP_LOG table in the Work Repository. You will need to do a series of joins to retrieve the exact table that was updated. Good luck with this...

  • Error while trying to add a SQL Script via DB02

    Good Morning and happy Sysadmin day to everyone,
    I have the following Problem regarding DB2 9.5
    I'm trying to run a SQL Script via DB02 in an ERP 6.0 System.
    I'm using DB02 -> Jobs -> SQL Script Maintenenace -> Add
    Then there is a Textfield "Script Name". When i'm using the F4-Help I'm getting the following error Message:
    List box value range for field DYN_SED-SCRIPT_NAME could not be created
    Message no. DB6PM004
    Any suggestions what might be the Error?
    Thanks in Advance
    Marco

    Are you trying to create a new Model or trying to import a Model ?

  • How to change maintenance powershell script via GPO?

    Per suggestion reposted from here: http://social.technet.microsoft.com/Forums/windowsserver/en-US/6eece9d6-a524-48aa-8e64-7554f0ec9b31/how-to-change-maintenance-powershell-script-via-gpo?forum=winserverGP
    Posted at http://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/desktop-shortcuts-to-items-on-network-drives/94eddb27-342b-40fc-9ad4-677ff4ee8ebe?page=9&tm=1403700614489 originally.
    There is a very annoying "feature" in Windows 7 called BrokenShortcuts.ps1 which is being called out weekly via maintenance task and if it finds more than 4 "broken" network shortcuts it removes them all. So it means if a user at this
    moment is disconnected from the network he will lose all links to shares, network applications sitting on his desktop. Funny that there was no such script on Vista and i don't see this on Win8. On the post i have attached one user suggested to edit this script
    and change 4 to 500 or whatever high number. That's fine for one time fix. But i need to do this for 200+ users. This file cannot be simply replaced by a script, so i'm wondering is there any way to do it via GPO?
    I have already tried various startup scripts, but i'm not sure which user to put into commands.
    I need to run this on startup:
    takeown /F C:\Windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1
    icacls c:\windows\diagnostics\scheduled\maintenance\TS_BrokenShortcuts.ps1 /grant "some user":F
    copy \\share\folder$\TS_BrokenShortcuts.ps1 C:\Windows\diagnostics\scheduled\Maintenance\ /Y

    You need to take time to study how Windows does these things.  You can control them with GP which is what you asked.  The article shows you how to disable elements of the tasks.  Each task controls a script.  If you disable the task the
    script that deletes shortcuts will be stopped. Other maintenance tasks will continue to run.
    Most of your problem is that you seem to want someone to provide a magical solution.  In technology it is necessary to fully research your issues until you understand all aspects.  After fully studying the issue you should understand the possible
    solutions if they exist.
    You claim to have deployed the patch that Microsoft released to fix the issue.  You claim it didn't work.  If that is the case then you need to call MS and \p[en a support incident.  If  Microsoft determines that you are right about the
    patch not working you will not be charged for the call.
    I know that learning how to support technology is hard and frustrating for newcomers.  In time, by using these incidents to learn, you will become a seasoned technician and all of this will seem trivial.  Until then we can only suggest that you
    do things that most of us are familiar with.  We cannot fix your network for you.
    I think you haven't really posted in the GP forum but posted a question about GP in the server forum.  Try posting in the GP forum.
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverGP
    Here is one answer from the GP forum:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverGP
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/600ca14f-8b1b-400c-b27f-a7f5733407ac/windows-scheduled-maintenance-task?forum=winserverGP
    ¯\_(ツ)_/¯

  • Edit Cluster Start-stop- and Monitor-Scripts via Bash?

    Hi,
    is there a way to edit (and sync!) the Cluster-Scripts via CLI?
    Regards
    Bernd

    The short answer is no. The scripts are stored in eDir, and NCS keeps revisions of them internally. The best place to edit them is iManager. Alternatively, you can directly change the eDir attributes for those scripts while cluster is down.
    That said, everything that iManager does comes in through a file interface. If you goal is to script resource modification, you can always access the file interface directly.
    Regards,
    Changju
    Originally Posted by toblerone
    Hi,
    is there a way to edit (and sync!) the Cluster-Scripts via CLI?
    Regards
    Bernd

  • View procedure scripts via catalog

    I have a suggestion for future implementation of Oracle CATALOG:
    It would be useful to see the procedures scripts via a kind of ALLPROCEDURES view, to make it easy to explore the relationships among functions and procedures and tables - well, to trace the plan of the application you're working at.
    I'm sure these data are already somewhere in the catalog (that's what "stored" procedure is supposed to mean), so it should not require a big effort by Oracle, but it would greatly benefical for development pourposes.
    Am I wrong?

    Actually DBA_SOURCE is containing only the stored procedures, functions and packages sorces. In order to find the relations between functions and tables for example you should use DBA_DEPENDENCIES.

  • Trying to deploy a VB Script via sccm 2012 R2

    Hello All
    This is my first attempt at deploying a script via SCCM 2012 R2 and I seem to be stuck. Essentially what this script does is map a printer. The script on its own works fine. Meaning it works when I double click it and also running it from the command
    line. Its  when I try to use in sccm things go down hill. I have tried the following from the command line in the package properties.
    \\my-sccm-server\Sources\Applications\VBSripts\cscript.exe Impact.vbs
    \\my-sccm-server\Sources\Applications\VBSripts\Impact.vbs 
    Phil Balderos

    looks good :)
    You can check execmgr.log on the client to monitor the install as it is running.
    Thank Richk,
    Still no luck. Here is the output from execmgr.log. Its saying that is completed but nothing ever happens. I am about ready to throw in the towel on this one but I just feel like that is should work because its such a simple script.
    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\srv-gtt-papercut\followme"
    WshNetwork.SetDefaultPrinter "\\srv-gtt-papercut\followme"
    Phil Balderos
    Is the script running as an Admin ,if so then you likely set the printer up for the local system user account and not anyone else.
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

  • Sending Script via Email

    Hi Folks,
                 I am able to send Script via mail to yahoo id with PDF attachment but not able to recieve the pdf attachment in gmail i.e. I get the mail in gmail but not with PDF attachment.
    Well in scot the output type is PDF.
    Thanks for responses in Advance
    <MOVED BY MODERATOR TO THE CORRECT FORUM>
    Edited by: Alvaro Tejada Galindo on Feb 4, 2009 9:24 AM

    Hi,
    check below links,
    /people/erwan.lebrun/blog/2007/04/16/tips-tricks-email-fax-through-the-same-output-type
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/mail%2bsend%2bthrough%2boutput%2bcontrols
    Regards,
    Madhu

  • Executing powershell script via task scheduler

    Hello,
    I am trying to execute powershell script via windows task scheduler which will forcefully delete all email in a mailbox, but I am getting the below errors
    Operational Code - 2
    Task Category - Action Completed --- Task Scheduler successfully completed task "\IL98" , instance "{2b193375-cbd2-4986-918d-3cfd4027d6b6}" , action "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" with return code 0.
    Last Run Result - 0X0
    When I am adding additional cmdlets in the script "Set-ExecutionPolicy Unrestricted", I am getting Last Run Result 0X5 rest of the error remains the same.
    Powershell version - 3.0
    Task Scheduler version - 1.0
    If I try to run the script manually via Exchange Powershell the script executes without any errors
    Thanks in Advance,
    Ankush Shah

    I figured out the problem, there wasn't any problem with the script but I had to correct inputs in windows task scheuler
    Below is the resolution:
    Under Actions:
        Program/Script --> ws\System32\WindowsPowerShell\v1.0\powershell.exe
        Add Argument --> -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto
    ; <filepath>"
    Eariler I was writing the filepath after double quote "
    Also I have selected the option "Run with Highest Privilages" to avoid
    0x5 error

  • Executing PowerShell script via JAVA

    Hi,
    I have simple powershell script as below :
    # Filename: Hello.ps1
    Write-Host
    Write-Host 'Hello World!'
    Write-Host "Good-bye World! `n"
    # end of script
    I wish to run this script via JAVA by the below JAVA code -
    import java.io.*;
    public class PsJava {
    public static void main(String[] args)
    throws IOException{
            Runtime runtime = Runtime.getRuntime();
    String cmds = (String)
    "cmd /C powershell C:/Documents and Settings/vvenkata/My         Documents/Hello.ps1";
            Process proc = runtime.exec(cmds);
            proc.getOutputStream().close();
            InputStream inputstream = proc.getInputStream();
                InputStreamReader inputstreamreader =
    new InputStreamReader(inputstream);
                BufferedReader bufferedreader =
    new BufferedReader(inputstreamreader);
    String line;
    while ((line = bufferedreader.readLine()) != null) {
                System.out.println(line);          
    Thanks
    Now, why is that I am not able to see any print statements from Hello.ps1 ? Can anyone help me on this?

    Hi,
    I have place my powershell script in the 'C' directory. and i have changed my JAVA code as below, but it still doesn't give any output in my Eclipse Console.
    import java.io.*;
    public class PsJava {
    public static void main(String[] args)
    throws IOException{
            Runtime runtime = Runtime.getRuntime();
    String cmds = (String)
    "cmd /c powershell c:/Hello.ps1";
            Process proc = runtime.exec(cmds);
            proc.getOutputStream().close();
            InputStream inputstream = proc.getInputStream();
                InputStreamReader inputstreamreader =
    new InputStreamReader(inputstream);
                BufferedReader bufferedreader =
    new BufferedReader(inputstreamreader);
    String line;
    while ((line = bufferedreader.readLine()) != null) {
                System.out.println(line);          
    Please advice me on this. If I have to create a batch file, then can you let me know how do I do that?
    Thanks

  • Actions loaded in script via in illustrator

    Dear Friend,
    i am having some actions(*.aia), those actions loaded in script via in illustrator. please help me.
    By,
    Seenuvasaragavan B

    help with what?
    You have not described any issues.
    Be aware, there's a bug in Ai which removes all scripts within actions as soon as Illustrator quits (exits). Actions will not retain script steps.

  • How to call business rules scripts via Java API

    Hi
    I have a problem. I have some scripts (business rules in essbase) that can be seen thru Administration Services Console under Business Rules folder. How can I execute these script using Provider Services (via Java API to EssBase interface)?

    hi
    i look too java api sample for "HBR Lounch"
    you can try found example in EAS folder
    C:\Hyperion\AdminServices\AppServer\InstalledApps\Tomcat\5.0.28\eas\webapps\hbrlauncher\MC_LaunchWindow.jsp
    please back, if you will have resolution :)

  • To View Calc Scripts and Report scripts via MaxL or Esscmd

    Hi all,
    Can somebody tell how to read any calc script or report script in any database with the help of MaxL or Esscmd?
    For example if there is any .csc or .rep file, I want to read the context of the file i.e. the script that is written in the file. Is it possible via MaxL or Esscmd?
    Does Hyperion supports this functionality?
    Regards,
    James

    You know that calc and report scripts are text files, right?
    They are typically stored in the database directory, although that is not a requirement; they can be stored in other client-accessible directories and run from there.
    I haven't done it in ages, but is also possible to pass calc and report scripts to Essbase via the API. I can't remember if the API will let you enumerate calc scripts from the database directory. I sort of strongly think yes. Someone who is more knowledgeable will either correct or refute that statement pretty soon. :)
    If you want to list the objects (calcs or reports): http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_techref/techref.htm
    A few things that you can do with MaxL re calc scripts:
    1) execute calculations, including a string that you pass through MaxL: http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_techref/maxl/ddl/statements/excalc.htm
    2) delete calculations: http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_techref/maxl/ddl/statements/drpcalc.htm
    3) list the calcs: http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_techref/maxl/ddl/statements/dispclc.htm
    4) create the calc: http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_techref/maxl/ddl/statements/crecalc.htm
    Report scripts are sort of a poor relation in MaxL (and were in Esscmd as well). You can basically only run a report as kind of export: http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/html_esb_techref/maxl/ddl/statements/exprt.htm
    So, I think it's mostly there, especially the display object command. BTW, if MaxL can list it, the API can too -- how else does MaxL work?
    Regards,
    Cameron Lackpour
    Edited by: CL on Dec 1, 2008 11:53 PM
    Didn't post the right URLs. Now fixed. CL

  • ORA-28579 when invoking an R script via rqTableEval

    Hi,
    I'm working with OBIEE SampleApp 406 virtual image. I managed to get almost everything to work there ... almost.
    Right now I'm trying to figure out why I'm getting ORA-28579 only in a very small number of occasions. For example:
    select id, image
    from table(rqTableEval(
    cursor(select 0 from dual),
    cursor(select 550 "ore.png.height", 550 "ore.png.width",1 "ore.connect" from dual),
    'PNG',
    'Multivariate Star Plot'))
    is throwing
    ORA-28579: network error during callback from external procedure agent
    ORA-06512: at "RQSYS.RQTABLEEVALIMPL", line 112
    ORA-06512: at "RQSYS.RQTABLEEVALIMPL", line 109
    28579. 00000 -  "network error during callback from external procedure agent"
    *Cause:    An internal network error occurred while trying to execute a
               callback to the Oracle server from the user's 3GL routine.
    *Action:   Contact Oracle customer support.
    To be honnest I don't have any idea where/how to investigate this any further. I have tried to fiddle with the memory limit at session level as advised at the url from hereunder:
    https://blogs.oracle.com/R/entry/managing_memory_limits_and_configuring
    Nothing worked.
    The R scripts are working just fine - tested via R Studio.
    Any ideas?
    Thanks,
    -Gabriel

    Further to this, I think that I found a pattern for the issue: it looks like the only scripts affected are those sourcing from BI Server:
    1. Multivariate Star Plot
    function(n){
    # BI Server Logical Query Example - In this example, results of logical sql is
    # rendered using R Graphics
    lSQL <- 'SELECT
    "Date"."Dep Month" Dim,
       "Delay Causes"."Carrier Delay as % of Arrival Delay" as Carrier,
       "Delay Causes"."Late Aircraft Delay as % of Arrival Delay" as LateAircraft,
       "Delay Causes"."Nas Delay as % of Arrival Delay" as NAS,
       "Delay Causes"."Security Delay as % of Arrival Delay" as Security,
       "Delay Causes"."Weather Delay as % of Arrival Delay" as Weather,
       100-("X - Airlines Delay"."Delay Causes"."Carrier Delay as % of Arrival Delay"+
    "X - Airlines Delay"."Delay Causes"."Late Aircraft Delay as % of Arrival Delay"+
    "X - Airlines Delay"."Delay Causes"."Weather Delay as % of Arrival Delay"+
    "X - Airlines Delay"."Delay Causes"."Nas Delay as % of Arrival Delay"+
    "X - Airlines Delay"."Delay Causes"."Security Delay as % of Arrival Delay") as Others
    FROM "X - Airlines Delay"
    WHERE "Date"."Dep Year" = \'2010\'
    ORDER BY 1'
    library("RJDBC")
    drv <- JDBC("oracle.bi.jdbc.AnaJdbcDriver","/app/oracle/biee/Oracle_BI1/bifoundation/jdbc/bijdbc.jar")
    conn <- dbConnect(drv, "jdbc:oraclebi://localhost:9703/", "weblogic", "Admin123")
    biData <- dbGetQuery(conn, lSQL)
    palette(rainbow(12, s = 0.6, v = 0.75))
    stars(biData, len = 0.8, draw.segments = TRUE, labels= biData[,c(1)],
    key.loc = c(6,-1), ncol=4, ylim=c(-2,8))
    dbDisconnect(conn)
    and  ...
    2. Balloon Plot
    function(n,
              dim1="Time.\"T03 Per Name Qtr\"",
              dim2="Products.\"P2  Product Type\"",
              metric="\"Base Facts\".\"2- Billed Quantity\"",
              cond="Time.\"T05 Per Name Year\" = ^2010^",
              dcol="skyblue"){
    cond<-gsub("^","\'",cond,fixed=TRUE)
    lSQL <- paste("SELECT",dim1,",",dim2,",",metric,"FROM \"A - Sample Sales\" WHERE",
                  cond,"ORDER BY 1,2",collapse=" ")
    library(RJDBC)
    drv <- JDBC("oracle.bi.jdbc.AnaJdbcDriver",
                "/app/oracle/biee/Oracle_BI1/bifoundation/jdbc/bijdbc.jar")
    conn <- dbConnect(drv, "jdbc:oraclebi://localhost:9703/", "weblogic", "Admin123")
    biData <- dbGetQuery(conn, lSQL)
    library(gplots)
    balloonplot( biData[,1],biData[,2],biData[,3],show.margins=FALSE, cum.margins=FALSE,
          label.lines=FALSE,ylab ="",xlab="",main=NULL,scale.method="volume",
          label.size=0.8,label.color="#787878",dotcolor=dcol)
    dbDisconnect(conn)
    Beside this, still no clue where to look further. Again, in both ORE and Rstudion these scripts are working fine. The only problem is with their embedded invocation via SQL ( rqTableEval).
    Thanks,
    -Gabriel

Maybe you are looking for