Problems understanding open text for access, please help

Hi all,
I'm experiencing some problems with this script, and I think knowing what the error is will help me a lot to understand better how applescript handles access to files.
When i launch this script it tells me somethihng like "document some object has not been opened" (could be slightly different in english).
So, i guess is a problem with openening and closing, but as you can see i open and close the doc, so I shouldn't encounter this problem. Do I?
Thanks for any tip!
set Report to "myfile.txt"
-- in case previously not closed I'll close again
try
  close access Report
end try
set the_file to (open for access Report with write permission)
write return to the_file starting at eof
write "test" to the_file
write return to the_file
write return to the_file
close access the_file
repeat with numero from 1 to 3
  write numero to the_file starting at eof
  write return to the_file
  write return to the_file
  close access the_file
end repeat

Each time your application is run the files associated with it will also be released, so all you need to do is make sure that each open is balanced with a close.  This can be done easiest by using a handler that has been tested, so you don't have to worry about leaving something out elsewhere in your script.  For example:
on run -- example
          set report to ((path to desktop) as text) & "myFile.txt"
  write_toFile_("testing one" & return, report)
  write_toFile_("testing two, three" & return, report)
  write_toFile_("testing again" & return, report)
end run
on write_toFile_(someThing, someFile)
  try
    set theOpenFile to (open for access someFile with write permission)
    write someThing to theOpenFile starting at eof
    close access theOpenFile
  on error -- make sure file is closed on any error
    try
      close access theOpenFile
    end try
  end try
end write_toFile_

Similar Messages

  • Having problems understanding f60genm error messages - urgent please help.

    Hi all,
    I'm a guy who has not a single idea about forms or form compilation. This is because I don't work with forms. The only reason that I am relaterd to forms is that i have a script that converts form files into a browsable web page (some thing like javadocs) which is being used by many people.
    my script converts a form file into txt file using f60genm and then the resultant txt file is converted to fmt file using f60genm. I am running my script from a RHEL server where a display variable is set.
    It was working fine all this while. But now i get error messages as this
    @ f60genm module=<form file name without the .fmb> batch=YES logon=NO forms_doc=YES...
    * CMD_FAIL_START
    @ * command failed: f60genm module=<form file name without the .fmb> batch=YES logon=NO forms_doc=YES
    * exit value: 0
    * core dumped: yes
    * signal received: 11
    * system message:
    * output:
    * CMD_FAIL_END
    Now my question is in what circumstances do i get this error message and what is it that f60genm trying to tell me by saying signal received 11?
    Is there any document or website where i can get all this information?
    Please help.

    Sorry guys,
    Just found that the error message that i pasted is not generated by f60genm.

  • Problem with pc suite for 8800 please help

    i have my nokia 8800 and want to send up some games, i have a usb bluetooth device and when nokia pc suit goes to pair with phone it says ok on the phone then on the pc it says
    Can not authorize phone, no com port available, please make a free com port
    but it has paired with phone, i have sent many items up to the phone but just wanted to try a game
    thanks for any advice or help

    this it what it says
    operating system:
    windows xp
    build 2600
    service pack 2
    bluetooth stacks
    IVT bluetooth stack
    version 1.6
    micrsoft bluetooth stack
    version 5.1.2600.2180
    any ideas ??

  • HT1365 Hi I have Imac 5 processor and I guess installed Lion I am having difficulty with Wifi connection. Sometimes after shut down number of times still does not access wifi or if it does I can see wifi bar on iMac but can't open any webpage. Please help

    Hi everybody,
    I have Imac 5 processor and I guess installed Lion I am having difficulty with Wifi connection. Sometimes after shut down number of times still does not access wifi or if it does I can see wifi bar on iMac but can't open any webpage. Please help
    Thanks

    Hello:
    There was an OS X 10.7 update released a month or so ago that fixed this problem.  Run software update.
    Barry

  • TS4185 I have downloaded facetime from the App store and I keep receiving this message - An internal FaceTime error occurred.  There was a problem with FaceTime. You need to quit and open FaceTime again.  Please help!

    I have downloaded facetime from the App store and I keep receiving this message - An internal FaceTime error occurred.  There was a problem with FaceTime. You need to quit and open FaceTime again.  Please help!

    This error message could result from an incorrect setting for date and time, or an operating system which does not have the latest updates installed.  It's a good idea to have your location setting on automatic.  Turn on the wi fi in your mac for a minute or so, to allow it to automatically search for your present location.  Do this even though you have the correct time Date settings displayed.

  • HT201407 My iphone suddenly stops working and asked for activation required. I did restore it thru itunes but it asks me to turn off "find my iphone". How can i disable "find my iphone" if i can open the iphone itself. please help me.

    My iphone suddenly stops working and asked for activation required. I did restore it thru itunes but it asks me to turn off "find my iphone". How can i disable "find my iphone" if i can open the iphone itself. please help me.

    My iphone 5 suddenly stops working and asked for activation required. I did restore it thru itunes but it asks me to turn off "find my iphone". How can i disable "find my iphone" if i can't open the iphone itself. please help me.

  • I do not use or have not signed up for a MobileMe Account but I am getting duplicates in my iCal for some reason.  All discussions I read are pointing to the MobileMe being the problem but it is not.  Please help me.  There must be another reason.

    I do not use or have not signed up for a MobileMe Account but I am getting duplicates in my iCal for some reason.  All discussions I read are pointing to the MobileMe being the problem but it is not.  Please help me.  There must be another reason all my entries appear twice. 

    If you wish to submit comments to Apple, the best way is to use their feedback pages.
    http://www.apple.com/feedback/itunesapp.html
    It's not likely that anyone from Apple will see your comments here among the thousands of other posts.
    Regards.

  • Hi, I have a problem with opening files on my desktop. When i double click a file I would lime to open nothing happens. Please help me with this problem :)

    Hi, I have a problem with opening files on my desktop. When i double click a file I would lime to open nothing happens. Please help me with this problem

    hello, this might be a preference in your google search settings. go to google.com/preferences and disable the option to ''Open search results in a new browser window''.

  • The account is invalid to access, please help me to connect to a new right email address. This is urgent for the pre-order, please respond as soon as possible.

    My email account is invalid to access, please help me to connect to a new right email address. This is urgent for the pre-order process, please respond as soon as possible.
    <Email Edited by Host>

    This is a user-to-user technical support forum. No one here can help you.
    Try
    https://expresslane.apple.com

  • HT1695 Hey, guys! I connected to the wi-fi by my iPhone (5) for 3 weeks. Now my iPhone doesn't connect to the network anymore. And I can't understand why. Will you please help me? It's strange,cause tonight I connected frequently. But now I can't! :(

    Hey, guys! I connected to the wi-fi by my iPhone (5) for 3 weeks. Now my iPhone doesn't connect to the network anymore. And I can't understand why. Will you please help me? It's strange,cause tonight I connected frequently. But now I can't! :(

    Hello LNIN5,
    Thank you for using Apple Support Communities!
    I have a couple resources for you to help troubleshooting wifi connection issues with an iOS device.
    The first is named iOS: Troubleshooting Wi-Fi networks and connections and can be found here http://support.apple.com/kb/ts1398.
    Take care,
    Sterling

  • Why is print in grey and PDF not a saving option for only one of my photoshop files?  All other files I open are fine.  Please help!

    I am trying to turn a photoshop document in to a pdf. Print is in grey and under Save As PDF is not an option.   Any other PS document I open allows me both options. What is wrong with this document?! 
    What I have tried and was unsuccessful:
    I changed it to illustrator and saved as PDF but the colors were very dark.
    I have renamed it and opened again.
    I duplicated the layers to another doc.
    Closed PS and opened it again.
    Please help. Thanks!

    Here is what I see...
    It is in RGB color / 32 bits/channel
    Any suggestions?

  • Reader XI 11.0.01: Shapes yes; sticky notes yes; highlighter/other text NO. Please help. Thanks.

    Reader XI 11.0.01: Shapes yes; sticky notes yes; highlighter/other text NO. Please help. Thanks.

    Thank you so much...
    2. [first] The problem is within the application; I wasn't trying while in a browser.
    3. There is no response upon clicking buttons, which prompted me to search for quite a long time in an attempt to find some "help," in case I was somehow performing the action incorrectly. [The Reader "Help" is in name only on this subject, but I can now see why...].
    1. [eureka] When I read your question #1 and began considering the possibility of corruption or something (the ever-lurking gremlins?) I realized that I was working with a PDF from a scan, and that that was probably the issue. I immediately opened one saved from a website and it worked perfectly and as expected. I opened a different scan-to-PDF and got the same original trouble.
    I'm glad one can still draw circles and attach sticky notes....
    Thanks again!

  • I have an iPhone 4s. After I updated to the Operating System 7, I cannot open the WiFi. Please help.

    I have an iPhone 4s. After I updated to the Operating System 7, I cannot open the WiFi. Please help.

    Try the suggestions here to see if they resolve your problem:
    http://support.apple.com/kb/ts1559
    If these don't work you may have a hardware problem. Visit an Apple store for an evaluation or contact Apple Support.

  • When i try to boot itunes, screen goes black and a message pops up and says not compatible with the visual elements. how do i fix this? itunes wont even open at this point. please help. thanks :)

    When i try to boot itunes, screen goes black and a message pops up and says not compatible with the visual elements. how do i fix this? itunes wont even open at this point. please help. thanks

    Let's first try the following document, only be sure that none of the boxes in the compatibility mode tab are checked (not just the compatibility mode box itself):
    iTunes for Windows: How to turn off Compatibility Mode

  • URGENT FIX MY Connect Four game for Wednsday PLEASE HELP

    I am using an APPLET and i want to use JOptionpane it didnt work when i used it in the paint method. So i want to make a runner to make the program work. I don't know why the Graphics g = new Graphics isnt working PLEASE HELP. Email the revised code to my email at [email protected]. URGENT FOR TOMORROW PLEASE HELP. should i have a spearate class for the runner, just email me please if you can help.
    import javax.swing.JApplet;
    import java.applet.*;
    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JOptionPane;
    public class Board extends JApplet
    // the grid used for storing the game layout.
    private int[][] grid;
    // the player whose turn it is.
    private int currentPlayer;
    public final int player1=1;
    public final int player2=2;
    private int place1=5;
    private int place2=5;
    private int place3=5;
    private int place4=5;
    private int place5=5;
    private int place6=5;
    private int place7=5;
    public static void main()
    int column1;
    int column2;
    String name1;
    String name2;
    Graphics g=new Graphics();
    Board test= new Board();
    boolean wait=true;
    while(wait)
    String starts=JOptionPane.showInputDialog("Are you ready? \n (yes or no)");
    starts.toLowerCase();
    if(starts.equals("yes"))
    wait=false;
    name1=JOptionPane.showInputDialog("Enter Player 1's Name");
    name2 = JOptionPane.showInputDialog("Enter Player 2's Name");
    test.paintBoard(true,g);
    while(!test.done() || !test.hasWon(g,player1) || !test.hasWon(g,player2))
    column1=0;
    while(column1>0 && column1<8)
    column1=Integer.parseInt(JOptionPane.showInputDialog(name1+" what column do you choose?"));
    test.place(player1, column1,g);
    if(!test.done() || !test.hasWon(g,player1))
    column2=0;
    while(column2>0 && column2<8)
    column2=Integer.parseInt(JOptionPane.showInputDialog(name1+" what column do you choose?"));
    test.place(player2, column2,g);
    public Board()
    // create the grid
    grid = new int[7][6];
    // initialize the gridc
    for (int row=0; row<6; row++)
    for (int column=0; column<7; column++)
    // set the position to a default value
    grid[column][row] = 0;
    public boolean done()
    boolean flags =true;
    for (int row=0; row<6; row++)
    for (int column=0; column<7; column++)
    if(grid[column][row] == 0)
    flags=false;
    return flags;
    public void paint(Graphics g)
    public void paintBoard(boolean flag, Graphics g)
    int index= 0;
    g.setColor(Color.YELLOW);
    g.fillRect(0, 80, 700,700);
    g.setColor(Color.WHITE);
    //draws spaces
    for(int y =100; y<700; y=y+100)
    for(int x =10; x<700; x=x+100)
    if(flag==false)
    index++;
    if(index%2==0)
    g.setColor(Color.RED);
    else
    g.setColor(Color.BLACK);
    else
    g.setColor(Color.WHITE);
    g.fillOval(x,y,80,80);
    TextField column =new TextField(10);
    if(flag==false)
    g.setFont(new Font("Times New Roman", Font.BOLD,24));
    g.setColor(Color.YELLOW);
    g.drawString("C",45,245);
    g.drawString("O",145,245);
    g.drawString("N",245,245);
    g.drawString("N",345,245);
    g.drawString("E",445,245);
    g.drawString("C",545,245);
    g.drawString("T",645,245);
    g.drawString("F",145,145);
    g.drawString("U",145,345);
    g.drawString("R",145,445);
    g.setColor(Color.BLUE);
    g.drawString("START",512,548);
    public void paintFinish(Graphics g, int player)
    int index= 0;
    g.setColor(Color.YELLOW);
    g.fillRect(0, 80, 700,700);
    g.setColor(Color.WHITE);
    //draws spaces
    for(int y =100; y<700; y=y+100)
    for(int x =10; x<700; x=x+100)
    index++;
    if(player==1)
    g.setColor(Color.RED);
    else
    g.setColor(Color.BLACK);
    g.fillOval(x,y,80,80);
    public boolean hasWon(Graphics g, int player)
    boolean status = false;
    // check for a horizontal win
    for (int row=0; row<6; row++)
    for (int column=0; column<4; column++)
    if (grid[column][row] != 0 &&
    grid[column][row] == grid[column+1][row] &&
    grid[column][row] == grid[column+2][row] &&
    grid[column][row] == grid[column+3][row] &&
    grid[column][row] == player)
    status = true;
    // check for a vertical win
    for (int row=0; row<3; row++)
    for (int column=0; column<7; column++)
    if (grid[column][row] != 0 &&
    grid[column][row] == grid[column][row+1] &&
    grid[column][row] == grid[column][row+2] &&
    grid[column][row] == grid[column][row+3]&&
    grid[column][row] == player)
    status = true;
    // check for a diagonal win (positive slope)
    for (int row=0; row<3; row++)
    for (int column=0; column<4; column++)
    if (grid[column][row] != 0 &&
    grid[column][row] == grid[column+1][row+1] &&
    grid[column][row] == grid[column+2][row+2] &&
    grid[column][row] == grid[column+3][row+3]&&
    grid[column][row] == player)
    status = true;
    // check for a diagonal win (negative slope)
    for (int row=3; row<6; row++)
    for (int column=0; column<4; column++)
    if (grid[column][row] != 0 &&
    grid[column][row] == grid[column+1][row-1] &&
    grid[column][row] == grid[column+2][row-2] &&
    grid[column][row] == grid[column+3][row-3]&&
    grid[column][row] == player)
    status = true;
    if(status)
    paintFinish(g, player);
    return status;
    public void place(int player, int column, Graphics g)
    int index=0;
    if(column==1)
    index=place1;
    if(column==2)
    index=place2;
    if(column==3)
    index=place3;
    if(column==4)
    index=place4;
    if(column==5)
    index=place5;
    if(column==6)
    index=place6;
    if(column==7)
    index=place7;
    grid[column-1][index]=player;
    if(player==player1)
    g.setColor(Color.RED);
    if(player==player2)
    g.setColor(Color.BLACK);
    g.fillOval((column*100)+10,(index+1)*100,80,80);
    if(column==1)
    place1--;
    if(column==2)
    place2--;
    if(column==3)
    place3--;
    if(column==4)
    place4--;
    if(column==5)
    place5--;
    if(column==6)
    place6--;
    if(column==7)
    place7--;
    }

    gamefreak1192 wrote:
    I am using an APPLET and i want to use JOptionpane it didnt work when i used it in the paint method. So i want to make a runner to make the program work. I don't know why the Graphics g = new Graphics isnt working PLEASE HELP. Email the revised code to my email at [email protected] URGENT FOR TOMORROW PLEASE HELP. should i have a spearate class for the runner, just email me please if you can help.
    This is bloody ridiculous. You want somebody to do your work for you, you can't be bothered to carry on a discussion here and ask for private email, and you expect somebody else to make your urgency (i.e. lousy time management) their problem. You got big brass ones, kid.

Maybe you are looking for

  • Photos will not sync  to PC

    About a month ago noticed that photos were no longer syncing with the PC. I love these photos and don't want to lose them. I've searched the discussion groups and can't find out what I need to do. Thanks!

  • ITunes card has no code. Can anyone help?

    I just scratched off the label on the back of an itunes card and there's no code. Has anyone else had this problem? There's just a sticky mess where the code should be. Any help would be appreciated.

  • Reg: Trial balance report for 2009 year

    Hi Consultants, We have requirement to report the GL Trial balance for 2009 year . Any one can provide me a query or advice me as it is urgent Thanks in Advance Anu.

  • How to apply Foreign Keys on top of a Common Lookup table

    I have an issue where i am mandated to enforce RI on an applications database (a good thing). but I have several common lookup tables where many of the "codes" reside for many different code types. I also have the mandate that i cannot change the und

  • Protocol Violation

    Hi, I have a problem run query from oracle database to sqlserver database using sql developer. Every time i run the query it give error "Protocol Violation". I use transparent gateway to link between my oracle database and sqlserver. When I use sql P