6 Replies Latest reply: Mar 1, 2013 10:36 AM by Frank Caggiano
madelefant Level 1 Level 1 (0 points)

In trying to do some Applescript programming that reads from a file I've hit a bit of roadblock. The applescript documentation refers to a pointer to the current read location in a file, but gives no listing of accessing it as a reference. For example. I have a file and I do a read unitl "whatever character."  It would seem highly useful there be a way to access the new or current read location as a built in propery or something.  It looks like the only way to really do this is to make your own secondary property/variable enumerating your position? So you have to set up a way to have a varialble that has a count of how far it has read in integer or character wise?

 

Maybe i am missing something.

 

Mike

  • Frank Caggiano Level 7 Level 7 (25,715 points)

    Perhaps if you explained what you were trying  a way could be suggested.

     

    Why do you need the absolute value of the file pointer?

  • madelefant Level 1 Level 1 (0 points)

    I have a file listing networks and servers for irc exported from Ircle (irc client).     Ircle doesn't have a setting to cycle through servers when one doesn't connect. (I think you can make it try the same one repeatedly). It needs to be able to read into a file to a specific network and then try each of the servers until it connects. The server file can change. The idea would be either to choose from a list of networks or enter a network, have it search into the file for that network and then try each of the servers.  If I create a list of the networks it has to read into the network name, then past the servers for that network and read the next server name to populate the list. I already have it reading the network names into a separate variable to be returned (having created my own pointer tracking thingy) but it is majorly sluggish.

     

    Mike

  • Frank Caggiano Level 7 Level 7 (25,715 points)

    How large is the file? Might be more efficient if you read the whole thing in and did the work in memory.

     

    Can you post some of the file or make it available online. Might be easier to visualize the problem if we can see the file.

  • madelefant Level 1 Level 1 (0 points)

    The file is about 40 k. This is the code snippet I have that is working but I thought I was maybe missing an built in applescript file position pointer.

     

     

    try

        close access serverList

    end try

    try

        set serverList to open for access file "Startup Disk MacPro:Users:michaelneal:Desktop:Programming:Server list"

    end try

    repeat

        try

            copy (read serverList from pointerLoc until "]") to end of networkStore

            copy (read serverList before "[") to end of serverStore

            set pointerLoc to the number of characters of ((networkStore as string) & (serverStore as string))

        on error

            exit repeat

        end try

    end repeat

    display alert the "File Position: " & (pointerLoc) & " EOF: " & (get eof serverList)

    close access serverList

     

    I have it pulling the network names and then the server names into different files just so I could test that it was working from the results as well as a display dialog for feedback.

     

    Here is a snippet from the file im reading:

     

     

     

    [AbleNET]

    A.AbleNET.org

    Defcon.AbleNET.org

    eXtreme.AbleNET.Org

    irc.ablenet.org

    Quantum.uk.AbleNET.org

     

    [AccessIRC]

    Copenhagen.DK.EU.AccessIRC.Net

    Warwickshire.UK.EU.AccessIrc.Net

    Lexington.KY.US.AccessIRC.Net

    Detroit.MI.US.AccessIRC.Net

    Hackettstown.NJ.US.AccessIRC.Net

    Florence.OR.US.AccessIRC.Net

     

    [AceStar]

    jailhouse.ma.us.acestar.org

     

    [AfterNet]

    Boston.AfterNet.Org

    IC5.EU.AfterNET.Org

    Flying-Dutchman.AfterNET.org

    London.AfterNet.Org

    TuX.AfterNet.Org

    suarez.NY.US.AfterNET.org

     

    [AlphaLink]

    irc.alphalink.com.au

     

    [AltNet]

    darkside.altnet.org

    ie.altnet.org

    phoenix.altnet.org

    rollingrock.altnet.org

     

    [Alternet]

    alternet.luc.ac.be

    alternet.cnmnetwork.com

    irc.eng.3sheep.edu

    alternet.bawx.net

    alternet.llamas.net

    irc.subtle.org

    alternet.wox.org

     

    [Ancients Net]

    chaos.ancients.net

    uranus.ancients.net

    wicked.ancients.net

     

    [Animenet]

    irc.aus.org

     

    [AnyNet]

    anynet.brimac.com

    irc.bluecherry.net

    irc.getsome.org

     

    [ArabChat]

    Bahrain.ArabChat.Org

    Beirut.ArabChat.Org

    Doha.ArabChat.Org

    Gulf.ArabChat.Org

    Khobar.ArabChat.Org

    KSA.ArabChat.Org

    Kuwait.ArabChat.Org

    Love.ArabChat.Org

    Oman.ArabChat.Org

    Palestine.ArabChat.Org

    Q8.ArabChat.Org

    Qatar.ArabChat.Org

    QualityNet.ArabChat.Org

    Riyadh.ArabChat.Org

    Saudi.ArabChat.Org

    UAE.ArabChat.Org

  • madelefant Level 1 Level 1 (0 points)

    I was abble to get this to do what I want using offset property. It is a roundabout way it seems but worked.

     

    Mike

  • Frank Caggiano Level 7 Level 7 (25,715 points)

    Given the layout of the servers file 9as shown in the example you posted) this code will read it into a list (aa) with the servename as one list item and the servers for tat serve as the next list item

     

     

    set fnum to open for access (((path to desktop) as text) & "Serverlist.txt")

     

    set aa to read fnum using delimiter {space, "[", "]"}

     

    repeat with i from 1 to length of aa

              if item i of aa is equal to "AfterNet" then

                        display dialog item (i + 1) of aa

              end if

    end repeat

     

     

     

    Depending on the file size and you machine this shouldn't be to much to run. You might want to give it a shot. With this then you can simply enter the serve name you are looking for and then access all its servers.