<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I trap an attempt to write to an open file? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468174#M71195</link>
    <description>&lt;P&gt;Many thanks Jim and Craige - I've now got a working solution that's an amalgam of both your recommendations.&amp;nbsp; I had to use the "Batch Interactive" command because the JMP Alert wasn't being sent to the log, but I couldn't get the logcapture() command to work, whereas &amp;lt;&amp;lt; get log() did what I needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I note that the log has to be cleared each time, or the same error message gets picked up on every subsequent run.&amp;nbsp; Just for the record, I've included a stripped-down version of my final script below.&amp;nbsp; (I'm guessing that the second "Batch Interactive(bi) term turns the interactive JMP Alert back on again - is that right?)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;OutputFileName = "$DESKTOP\My Slides.pptx";

if(not(file exists(OutputFileName)),

	// No possible problem here;

	Text Box("New File - First Page") &amp;lt;&amp;lt; save presentation(OutputFileName);
	caption("You've just started a new presentation - here it is..."); wait(2); caption(remove);
	open(OutputFileName)

	,

	// The file exists but it might be open - so be wary;

	bi = Batch Interactive( 1 );

	// If I don't clear the log first, it will tell me there's an error even when there isn't;
	
	clear log();
	Text Box("Existing File - Next Page") &amp;lt;&amp;lt; save presentation(OutputFileName, append);
	Error_List = get log();

	if(contains(concat items(Error_List), "Unable to overwrite"),
	
		beep();
		caption("You can't write to the file\!rbecause it's open right now.\!rPlease close it, then try again.");
		wait(3);
		caption(remove);
		Batch Interactive(bi)
		
		,
		
		caption("Here's the updated presentation with your latest slide"); wait(2); caption(remove);
		open(OutputFileName)
		
		)
		
	);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 09 Mar 2022 19:33:32 GMT</pubDate>
    <dc:creator>DMR</dc:creator>
    <dc:date>2022-03-09T19:33:32Z</dc:date>
    <item>
      <title>How can I trap an attempt to write to an open file?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468038#M71188</link>
      <description>&lt;P&gt;Hi - I have a JSL script that prompts the user to save a selection of JMP graphics that have just been generated by an analysis directly to a PowerPoint presentation.&amp;nbsp; The user is likely to want to inspect the resulting slides immediately, so I don't want to close the PowerPoint file automatically - but if the user then tries to append any &lt;EM&gt;more&lt;/EM&gt; graphics to it with a second run of the script, they'll get a JMP Alert telling them they're trying to overwrite a file that might be open in another program (which of course it is).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried trapping an attempt that could fail with the Try() function, but this doesn't seem to work: the error occurs anyway - and although the JMP Alert does correctly tell the user what the problem is, I don't really want error messages interrupting the flow of the program.&amp;nbsp; I thought using the "Is File Writable()" function to check it in advance would deal with it, but that doesn't seem to work either: the PowerPoint file &lt;EM&gt;is&lt;/EM&gt;&amp;nbsp;deemed to be writable, even though it's open.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the moment I'm putting up a message on the screen - if the file already exists (which obviously I &lt;EM&gt;can&lt;/EM&gt; check for) - warning the user in advance that &lt;EM&gt;if&lt;/EM&gt; it's open, they'll need to close it before proceeding - but this is a bit inelegant and doesn't really solve the problem.&amp;nbsp; Is there a way to automatically (a) check that it isn't open already, and (b) close it if necessary?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 11:22:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468038#M71188</guid>
      <dc:creator>DMR</dc:creator>
      <dc:date>2023-06-11T11:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I trap an attempt to write to an open file?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468081#M71192</link>
      <description>&lt;P&gt;You can use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;mylist = get log();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then parse through mylist to see if the warning occurred and if it did, then take the action you want to take.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 13:50:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468081#M71192</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-03-09T13:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I trap an attempt to write to an open file?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468082#M71193</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;txt = logcapture(...jsl that might make log messages...)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;could also help with the same approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;edit: You might need &lt;LI-MESSAGE title="Create Database Connection Error" uid="441513" url="https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441513#U441513" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp; too, which shows how to use BatchInteractive() to suppress a dialog and just get a log message. ...and &lt;A href="https://community.jmp.com/t5/Discussions/Open-Excel-within-a-button-box-Strange-behavior/m-p/385682/highlight/true#M63579" target="_self"&gt;more on batch interactive&lt;/A&gt; .&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 14:16:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468082#M71193</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-03-09T14:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: How can I trap an attempt to write to an open file?</title>
      <link>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468174#M71195</link>
      <description>&lt;P&gt;Many thanks Jim and Craige - I've now got a working solution that's an amalgam of both your recommendations.&amp;nbsp; I had to use the "Batch Interactive" command because the JMP Alert wasn't being sent to the log, but I couldn't get the logcapture() command to work, whereas &amp;lt;&amp;lt; get log() did what I needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I note that the log has to be cleared each time, or the same error message gets picked up on every subsequent run.&amp;nbsp; Just for the record, I've included a stripped-down version of my final script below.&amp;nbsp; (I'm guessing that the second "Batch Interactive(bi) term turns the interactive JMP Alert back on again - is that right?)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;OutputFileName = "$DESKTOP\My Slides.pptx";

if(not(file exists(OutputFileName)),

	// No possible problem here;

	Text Box("New File - First Page") &amp;lt;&amp;lt; save presentation(OutputFileName);
	caption("You've just started a new presentation - here it is..."); wait(2); caption(remove);
	open(OutputFileName)

	,

	// The file exists but it might be open - so be wary;

	bi = Batch Interactive( 1 );

	// If I don't clear the log first, it will tell me there's an error even when there isn't;
	
	clear log();
	Text Box("Existing File - Next Page") &amp;lt;&amp;lt; save presentation(OutputFileName, append);
	Error_List = get log();

	if(contains(concat items(Error_List), "Unable to overwrite"),
	
		beep();
		caption("You can't write to the file\!rbecause it's open right now.\!rPlease close it, then try again.");
		wait(3);
		caption(remove);
		Batch Interactive(bi)
		
		,
		
		caption("Here's the updated presentation with your latest slide"); wait(2); caption(remove);
		open(OutputFileName)
		
		)
		
	);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Mar 2022 19:33:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-can-I-trap-an-attempt-to-write-to-an-open-file/m-p/468174#M71195</guid>
      <dc:creator>DMR</dc:creator>
      <dc:date>2022-03-09T19:33:32Z</dc:date>
    </item>
  </channel>
</rss>

