Applescript: File remains "open" even if trashed and gone

re: simple text file written in AS alone, outside Finder:
1. I write to a file like this:
  set thisFile to open for access aFilePath with write permission
  — do stuff
  close access thisFile
As long as "do stuff" executes OK., the close access is hit and I can use the file over and over. I have no problems with this script. But:
2. If “do stuff” hits an error, it leaves me with an unusable file. Even when the file is trashed and gone (Secure Empty Trash), if I ever try to use the same file name, AS will first create the file, but immediately pop an error that that file is already open before I can do anything else. The system is remembering the file name and flagging it as open (apparently).
3. So I try to close it:
      set thisFile to file aFilePath
      close access thisFile
and I get no error on the first line but a  “ ... [correct path to "thisFile"] cannot be made into type file" error on the second line.
Question 1: If "thisFile" is a file on the first line, then why not on the second? Why does "close access" which works in item 1 above, fail here?
So any new file name works as long as "doStuff" works, but I can't use any file name that didn't close the first time through. I cannot seem to close the file after the fact, even when it's been trashed.
Question 2: how do I tell the system that this file is not open or does not exist?
Great thanks for your help!

I'm guessing that this is happening to you while running the script in the script editor.
When a script is run in the editor it is the editor that actually has the file open and if the script exits without closing the file the editor gets hung.  Any open files are automatically closed when the application exits but as it is the editor that has the file open the file is not closed when the script exits only when the editor exits. So one work around is to close the editor and restart it.
However the correct way to handle this is to the file work in a try on error block. See Introduction to AppleScript Language Guide specifically the section Close access, the command used to close an open file, for more details.
The basic idea
set aFile to choose file
set fp to open for access aFile
try
  --file reading and writing here
on error e number n
  --deal with errors here and don't resignal
end try
close access fp

Similar Messages

  • Open quantity remains open even when delivery and goods issue is completed

    Hi gurus,
    We have so many deliveries in system where open quantity  in outbound delivery document  shows the quantity as open even though the goods issue is completed and invoice has been created and accounting documents are also cleared.
    I am not getting why it is happening. can someone please advise or throw some light on this.
    Vice versa they are showing up in MRP run as requirements.
    Thanks in advance gurus,
    Kind regards,
    Gopio.

    Hi Amol,
    I think i got the correct one which is RVV05IVB, and i had selected the shipping due date index, but it did not clear the open quantity, still it remained as open quantity.
    And the message i got after running the report is pasted below.
    Reorganization of SD Document Indices
    Reorganization sales document indexes with the following selection criteria:
    I EQ 80015593
    Delivery due Index
    How does that open quantity gets updated, or is there any control that we can deactivate as these are showing up in MD04 as sales requirements.
    Thanks,
    Regards,
    Gopio.

  • I just downloaded Digital Editions to use an e-book I purchased.   When I try to open the file it opens in Adobe Reader and I get an error message.  Please help

    please help  I downloaded Digital Editions to use e-book and when I got to open I get an error message

    It says file could not be opened because it was either not a supported type or it was damaged.  I have already had the file resent and in talking to the American Medical Association (purchased from their site)  it appears when I go to open the file it is in Adobe Reader and I do not see an option to move it to Adobe Digital Editions,
    Kathy Harlan
    <mailto:[email protected]> [email protected]
    Cell: 214-850-6427

  • JNLP file not opening in Windows 8 and IE 10

    I am trying to launch the ROES ordering tool through WHCC prints and it has always worked on my other IE 10 through Windows 7 but on my new computer with Win 8 I cannot get it to launch because of the JNLP file not opening... and it won't work on desktop
    mode either... What do I need to do??

    Hi,
    Have you installed the java Runtime Environment?
    If not, I would also suggest you to refer to the link to install the latest version of Java:
    http://www.java.com/en/
    Please note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    Then follow the link to set default programs as Java for the file:
    Choose the programs
    Windows uses by default
    http://windows.microsoft.com/en-US/windows-8/choose-programs-windows-uses-default
    Hope this helps,
    Ada Liu
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Black window remains open even after closing the window programatically

    I have an application which has multiple windows. From mainwindow button click event I am closing the child form of the application. The child window is opened after a successful socket, serial or gateway connection attempt, after which the application
    do work with some threads and while clicking on a button on mainwindow I am closing this child window after disconnecting the respective connection mode. But after the close event the child window background gets black and it remains open unless and until
    I just do a minimize and maximize the application. Please help me on this to get this issue fixed.

    Well the details are rather going to depend on what it's doing.
    It's a very open ended question really.
    But...
    Your options include.
    Background worker.
    https://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx
    DIspatcherTimer
    https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer(v=vs.110).aspx
    Async Await
    https://msdn.microsoft.com/en-us/library/hh191443.aspx
    Tasks
    Task.Factory.StartNew(() => { Dosomething(); });
    Or just a plain thread
    using System.Threading;
    new Thread(() =>
    Thread.CurrentThread.IsBackground = true;
    // DoSomething();
    }).Start();
    Where DoSomething is a method.
    You can also have inline code of course instead of a method.
    Whilst on a different thread to the UI you can't update UI objects.
    You'll get a thread affinity error message if you try.
    That means you either return your results to the ui thread and process them there ( particularly convenient with async await ).
    Or you update something which doesn't have thread affinity.
    An observablecollection bound to an itemssource doesn't have thread affinity eg.
    You do need to raise property changed at the end of your processing with that option because it notifies collectionchanged on the wrong thread and the UI won't know it changed.
    Or you can dispathcher.begininvoke to get back to the UI thread.
    All depends what you're doing but hopefully one of those options there will suit you.
    Hope that helps.
    Recent Technet articles:
    Property List Editing ;  
    Dynamic XAML

  • On some sites when I click a link to upen a pdf file Mozilla opens a new tab and nothing happens. Why is this happening?

    When the new tab opens in the address bar it shows About:Blank. If I switch to the IE engine it will download the PDF file without any problems so I'm wondering why Native Mozilla is having this problem opening the PDF file. It's a real hastle switching engines, especially when I'm logged into something like a bank web page because I have to re-log in to the site a second time as switching engines cancels my original log-in.

    Couldn't it also be the way Mozilla processes things which differ from IE? It works every time I use the IE engine add on which tells me that either Mozilla is processing things differently or that IE is doing something different. I've heard that IE doesn't always follow the same HTML standards that Mozilla does. Could this be the difference and would it be something that Mozilla could change to process the same as IE?

  • My antivirus found and removed a virus called Hijacker.DosPop_Toolbar, and now Firfox browser will not open, even with uninstall and reinstall?

    I have uninstalled version 8 and tried to go back to an earlier version, but browser still will not open.

    Delete the Program Files for Firefox and install a freshly downloaded Firefox_setup file.
    http://www.mozilla.com/en-US/firefox/

  • Itunes constantly crashes and won't open even efter removal and re-install.

    It states "AppCrash" as the reason. I've removed all the hardware, and reinstalled it just to have itunes quickly open upon startup, immediately close again and state it was an app crash.

    Thank you all for your input and sympathy! I did reset the PRAM before taking it in on Sunday, but that unfortunately didn't do it. I also tried the erase-then-install route, but the machine only gets through varying degrees of the install before crashing.
    I hauled it up to the Apple Store (150 mi. RT, but great guys/fast service) who also believed it was RAM, swapped out the apparently 3rd party RAM (who would think you would have to specify APPLE RAM to an Apple Specialist/Reseller?!). Turns out it still crashes, so back I went on Monday. It's now waiting on a logic board and processor.
    I've always bought direct from Apple before, but tried to save a few $ this time. Needless to say, those saved $ have been spent several times over in time and mileage, some of which would have been spent regardless of where the machine came from. However, had I bought direct, I could probably get a new machine more quickly at the store. If the machine isn't running wthin a week I will send it back west for an exchange. Thank you again. I'll follow up here when this is resolved.

  • How do I create links between two pdfs using FrameMaker 9, while both files remain open?

    In FrameMaker 9 is there a way to create cross reference to a particular page on another doc (without closing the current/source doc)?
    I tried using "openpage filename:pagenumber" option, the link takes me to page 1 of the referenced doc not to the specified page, and as it is a hyper link when page 1 of the referenced doc gets displayed the souce doc closes.
    When a link is clicked in the source doc, it is required that the source doc remians open.
    This is an urgent requirement, can anyone please reply soon?

    I think you've already asked this in this thread - http://forums.adobe.com/message/5613200#5613200 - and it's been answered there.

  • Connection remains opened even after calling conn.close

    i have a need to copy records from one table in a database (say db1) to another table in another database(say db2). I open connection to both databases, and get a Recordset (say rs1) by executing a query that contains all rows that i have to insert in the database db2. Next i get an empty recordset(rs2) on the table in the database db2 (with locktype batchoptimistic, clientside cursor). i loop on rs1 and for each row in rs1 i insert a row in rs2 and copy the fields. after all rows are done, i delete the rows from db2 that will be affected and do an updatebatch on rs2. then i close the recordsets and the connections
    everything works fine except that the connection with the db2 is not getting closed, neither is it throwing any exception. when i comment the updateBatch code the connection closes normally.
    can anyone please help me out, where am i going wrong.
    thanks
    Vijay Sharma

    Hi,
    There is one more thing that I want to add to the above question. After calling conn.close() I checked the status of the connection and it was not 'OPEN' but when I checked session information through DBA studio it was showing one connection. I enabled trace of Oracle provider for OLE DB. Trace showed that two sessions were opened but only one session was closed.
    Thanks,
    Vijay

  • I receive pdf files that open with checkered background and I can't read them.

    Lately, whenever I open a pdf attachment  from someone, it opens in Adobe with a checkered background.  How do I get rid of this background?

    Hi Barbara:
    Thanks for your reply.
    I have a PC.  How do you set the Reader to open pdf instead of Elements?  When I open my email and it has a pdf attachment, I click on it, it scans it and asks if I want to open it.  It then opens automatically in Elements - with no other option. 
    I invite you to see my website: www.zhibit.org/marlenelevitt

  • BB10 File Manager keeps showing previously linked (and gone) computer

    Hi. After upgrade from 10.2.1 to 10.3.1, access to / from my paired computer stopped working.  I tried removing and readding it and apparently ran into a bug.  In Device Connections I have my computer linked again BUT in File Manager I can see it twice ("mylaptop (offline)", "mylaptop-1") and I've no idea how to get rid off the former (original).  If I remove the computer in Device Connections then just "mylaptop-1" disappears from File Manager and the other entry stays there and unusable.  How to fix it please ?

    hmm, this somehow fixed itself after two weeks or so.  but i'm not very confident about bb file manager now, especially as i ran into issue with sd card and file manager showing incorrect info.  it seems there's some caching which may persist even after phone restart..?  fishy to say the least :-/

  • Can a Compiled and saved AppleScript File be modified?

    What I mean is, If i were to create an AppleScript file with default variable, functions etc. Could I,say sometime in the future, edit those variables dynamically?
    So for example, I have a script file that customizes an XCode project and  creates an .app file and an .ipa file. Would it be possible to edit the Applescript file, thereby generating a new .app and .ipa file?
    Send  Parameters to -----> Default AppleScipt file ---> Modified AppleScript File ----> New .app and .ipa File

    Hello
    You can use "load script" command and modify the properties of loaded script. Something like this:
        [1] a.scpt is assumed to be coded :
    property p : 0
    tell application "SystemUIServer"
        activate
        display dialog "p = " & p
    end tell
        [2] When b.scpt is opened in AppleScript Editor, decompiled source shows exactly the same as a.scpt
            although its property p's current value is not 0 but 1 as set in this script.
            In other words, decompiled source code shows static value as defined in source code
            whilst the loaded script stores and uses dynamic value at runtime.
    -- load script
    set f to (path to desktop)'s POSIX path & "a.scpt" -- [1]
    set o to load script POSIX file f
    -- run it (p = 0)
    tell o to run
    -- modify it
    set o's p to 1
    -- run it (p = 1)
    tell o to run
    -- store modified script to new file
    set f1 to (path to desktop)'s POSIX path & "b.scpt" -- [2]
    store script o in POSIX file f1 with replacing
    -- load modified script from file
    set o1 to load script POSIX file f1
    -- run it (p = 1)
    tell o1 to run
    If you want to modify the source code, you may use osadecompile(1) and osacompile(1). Something like this:
    #!/bin/bash
    cd ~/desktop || exit
    osadecompile a.scpt | perl -CSDA -lpe 's/property p : 0/property p : 2/' | osacompile -o c.scpt
    osascript c.scpt
    Or to run modified script without saving:
    #!/bin/bash
    cd ~/desktop || exit
    osadecompile a.scpt | perl -CSDA -lpe 's/property p : 0/property p : 2/' | osascript -
    * The above is true for plain AppleScript script. Don't know about AppleScriptObjC script. Also in recent OSes, applet might need to be re-signed after modification.
    Regards,
    H

  • Applescript to add open images in Preview into iPhoto?

    I've got an eyefi card in my digital camera that sends my pics directly to a folder on my laptop in which a folder action runs that automatically opens the image in preview. What I'd like to do next is to close the images I don't want, and then run an applescript that will take the remaining open images in Preview and import them into iPhoto.
    I guess if I were to do it manually, I would drag the proxy icon of each window into iPhoto? But that would create several separate events in iPhoto since it would import them one at a time. It would be ideal if there was a way for Applescript to locate the open images in finder, and then import all of those images into iPhoto all at once. Is this possible? If so, any tips on how to get started with that? I'm a newb to Applescript, so be gentle.

    It sounds like you've been doing the search in the menubar Spotlight field. If so, here are two things to try:
    One, when you have located the image you think you want to open, hit Command-Return, which will open (in a new Finder window) the folder in which the image file is located, even if it is inside your iPhoto library. The default application for opening the image then should be Preview (it is for me).
    Two, select "Show All" at the top of the results, which opens a Finder search window. An image file in the resulting list, even if it is inside the iPhoto package, will open by default in Preview (That's what it does for me.)
    Hope this helps.

  • My startup disc is full and I want to find out the size of trash and junk in mailbox before dumping trash & junk

    I have gotten this message saying that my startup disc is full.
    I know I need to dump the trash can on my home screen and I have done that.
    I know that there is both trash and junk in my mail app that I will dump also but I am curious as to the size of the trash and junk in mail but I don’t see how to find the sizes.
    Its nice that the Junk tells me that there are 739 messages but it doesn’t say what the size of all of them is.
    Do you know how i can see what the file sizes are for trash and Junk in Mail?
    I know I can just delete them and see how much this yellow bar decreases but that seems like a crude way to see what the file sizes are that I have deleted.
    If you have an answer for how to find out the file sizes of the Mail trash and junk I would like to know how to do it.
    I have the latest version 10.9.4 on my Mac Air.

    do you have the Size Column selected in the View pulldown?

Maybe you are looking for

  • Automatic PO Creation thru assign PR to source of supply (me57)

    Hello, I'd like to have an automatically created PO out of my PR thru ME57. I assign the PR to a source. and press the nice button for generate PO. But then it doesn't generate the PO, it just shows me the me21n with the PR in the document overview i

  • ACS 5.3, ASA using TACACS+ forces to PAP?

    As the title says I'm trying to have an ASA (8.2.3) auth against an ACS 5.3 using TACACS+.  It only works if I have PAP enabled on the ACS.  Obviously this concerns me.  I've found the following reference in the configuration guides: TACACS+ Server S

  • Lockbox partial application

    Hi, By default, when lockbox payments come, the partial payments are posted as residual items and the original invoice is cleared . We need to keep the AR original invoice open and post the incoming as partial payment. Where do we configure this? ANy

  • HT204291 no video using Airplay from DVD

    I can see my desktop and a video window appears on both my MBP (2012 model) and on my TV but the image of the DVD I'm trying to play shows a checkerboard pattern.  The audio passes through just fine.

  • Add an Admin user to external boot drive?

    I installed Mavericks to an external drive; all went well except when I booted from it and tried to add printer drivers it appears I only have a "Standard"-level user account and nothing else (Guest not enabled). I've never seen anything like this be