nicholas eve

Q: old appleworks files

I have got loads of files from about 10+ years ago or so. When I try to open them it says old version of appleworks can't open. Is there any software that can extract the text, I'm not bothered about formating or anything else, just the raw text.

Posted on Oct 17, 2013 8:00 AM

Close

Q: old appleworks files

  • All replies
  • Helpful answers

first Previous Page 3 of 5 last Next
  • by Peggy,

    Peggy Peggy Dec 26, 2013 9:20 AM in response to rrobelen
    Level 8 (38,720 points)
    Applications
    Dec 26, 2013 9:20 AM in response to rrobelen

    AppleWorks 6.2.7 was the worst update in the history of AppleWorks but, in this case, it's better than 6.2.9.

     

    Peggy_sig.png

  • by rrobelen,

    rrobelen rrobelen Dec 27, 2013 2:17 PM in response to Barry
    Level 1 (0 points)
    Dec 27, 2013 2:17 PM in response to Barry

    Hi Barry,

    I am in trouble. 

    Through one of your other discussions I found a nice applescript by the Frenchman that opens AW5 files and saves them in AW6.  I ran it and it worked as advertised.  But it had one small flaw.  It looked at file names and if they were more than 22 characters it did the truncate and append hex string.  I have seen this scenario before so I went into the code and changed the test to be > 100 instead of 22.  This fixed the problem. 

    But all of sudden any file over 22 characters just opened into AW6 either through Finder or AW5 itself gets the truncate treatment. No applescript running.   If I open the same file to say TextEdit it does not get truncated.  Its like something has been turned on in AW5 that now truncates all file names greater than 22.  I swear it was not doing this before i ran the Frenchman's applescript.  Does this ring a bell with you.  I am running the Mac with logmein but i had the person the at the computer restart it to no avail.  searching has turned up nothing.  Help!

    Russ

  • by rrobelen,

    rrobelen rrobelen Dec 27, 2013 3:21 PM in response to rrobelen
    Level 1 (0 points)
    Dec 27, 2013 3:21 PM in response to rrobelen

    I should add this - It behaves in AW 6 as if I am running under OS 9 instead of OS X 10.6.8

  • by rrobelen,

    rrobelen rrobelen Dec 28, 2013 1:46 PM in response to rrobelen
    Level 1 (0 points)
    Dec 28, 2013 1:46 PM in response to rrobelen

    First - my initial thought that this was like the long file name truncation was wrong.  It is something different.  I have narrowed the problem down to this. 

    Not all the files have their names altered.  While all the files end in the extension ‘.cwk’, character strings preceding the ‘.cwk’ factor into the altered file names.   I found the following unique endings among the 238 files.  Most end in just ‘.cwk’ but about 70 of them have one of the following ending:

     

    (AWk.cwk

    (AWks.cwk

    (AWks5.cwk

    (AWks5) .cwk

    (AWks5) [.cwk

    (AWks5) [.cwk

    (AWks5) [v.cwk

    (AWks5) [v6.cwk

    (AWks5) [v6..cwk

    (AWks5) [v6.0].cwk

     

    The files that get altered names when opened have some of these endings replaced with strings like ‘#42D0F56.cwk’.  For example file name '20 ALARMS -SECURITY (AWks5) [v.cwk' is changed to '20 ALARMS -SECURITY#42D0F56.cwk'.

    Before I test all the files to see which ones are altered I am hoping someone can tell me what these ending mean.

  • by Hiroto,

    Hiroto Hiroto Dec 28, 2013 9:50 PM in response to rrobelen
    Level 5 (7,276 points)
    Dec 28, 2013 9:50 PM in response to rrobelen

    Hello

     

    First of all, tell us which script of Yvan Koenig you're trying to use. Without knowing it, it is impossible to help.

     

    As for #XXXXX which appears at the end of some document name in AppleWorks, it is catalogue node id of the file in HFS+ volume. AppleWorks is an old beast which only accepts the maximum of 31 characters in document name and when the file name (HFS+ name) in volume is longer than that, it truncates the name and embed the catalogue node id at the end (but before file name extension if present).

     

    * Catalogue node id is the unique id of each node in HFS+ volume and embedding it in truncated file name used to be the common method to handle long file name in applications which do not support long file name.

     

    Regards,

    H

  • by rrobelen,

    rrobelen rrobelen Dec 29, 2013 4:23 AM in response to Hiroto
    Level 1 (0 points)
    Dec 29, 2013 4:23 AM in response to Hiroto

    Hello,

    Thanks for your reply.  It is very helpful.

     

    The script from Yvan Koenig is his 'AW save As 6' script. I hope he will excuse my calling him the Frenchman.  I meant no disrespect only that I had forgotten his name at the moment I was typing.  I show it below.

     

    With your explaination I now see that he was just parsing long file names that get truncated.  The first file name I tried just happened to truncate just before one of the long endings that I thought meant something.  The meaning of these endings is still a question.

     

     

    -- [SCRIPT AW save As 6]

    -- -------------------------------------

    (*

    ExŽcutez ce script,

    le document AW au premier plan nommŽ monDoc

    sera enregistrŽ sous le nom monDoc´0001

    ˆ l'appel suivant sous monDoc´0002

    puis monDoc´0003 É

    En fin de session, aprs avoir vŽrifiŽ que le dernier

    exemplaire est lisible, vous pourrez jeter les prŽcŽdents

    Peut s'utiliser:

    - depuis le bureau,

    - depuis le menu Scripts d'AppleWorks

    - tre associŽ ˆ un bouton.

    Il existe mme un utilitaire permettant d'associer une

    application (pourquoi pas celle-ci) ˆ une touche de fonction.

     

     

    Run this script,

    the front AW document will be saved as

    myDoc´0001

    then myDoc´0002

    then myDoc´0003

    When the session is done, check that the last copy is OK.

    If it is you may trash the lower ones.

    One may call it:

    - from the desktop

    - from AppleWorksÕs Scripts menu

    - from a linked button.

    There is an utility allowing us to link an application

    (why not this one) to a function key.

     

    Yvan KOENIG

    le 24 avril 2004 ˆ Vallauris (France)

    modifiŽ le 29 avril 2004

    *)

    -- -------------------------------------

     

    property french : true -- true = franais, false = anglais

    property extension : ".cwk"

    property Borne : "´" -- surtout PAS le diese #

    property ellipsis : ASCII character 201

     

    property msg0 : ""

    property msg1 : ""

    property msg2 : ""

    property msg99 : ""

     

    on run

    try

    set vieuxDelim to AppleScript's text item delimiters

     

    if msg0 is "" then my prepareMessages()

     

    tell application "AppleWorks 6"

    activate

    set laVersion to version as text

    if ("6." is not in laVersion) then Â

    error msg0 number 8000

    (* Ce script n'est pas compatible

    avec cette version dÔAppleWorks.

    ¥ This script is not compatible

    with this version of AppleWorks. *)

    if (count each document) < 1 then Â

    error msg2 number 8002

    (* "Aucun document ouvert"

    ¥ "No open document" *)

     

    set leChemin to (file of front document) as text

     

    if leChemin is "false" then error msg1 number 8001

    (* cas d'un fichier d'une "ancienne version"

    ¥ Take care of documents issued from old AW*)

     

     

    tell application "Finder"

    activate

    try

    set laFamille to ""

    set laFamille to (label index of file leChemin) as text

    end try

    end tell -- to Finder

     

    if my quelOS() is true then

    tell application "Finder"

    activate

    set leDossier to (container of file leChemin) as text

    (* fonction disponible dans OSX, pas dans OS9

    ¥ available in OSX, not in OS9 *)

    end tell -- to Finder

    else

    set AppleScript's text item delimiters to ":"

    set maListe to text items of leChemin

    set item -1 of maListe to ""

    set leDossier to (maListe) as text

    set AppleScript's text item delimiters to vieuxDelim

    end if

     

    set nom1 to (name of front document) as text

    if nom1 ends with extension then

    set nom2 to text 1 thru -(1 + (count of extension)) of nom1

    (* garde ce qui prŽcde

    ¥ keeps what is before the extension. *)

    set avecExtension to true

    else

    set nom2 to nom1

    set avecExtension to false

    end if

     

    if ((count of nom2) > 20) and (character 21 of nom2 is "#") then Â

    set nom2 to (text 1 thru 20 of nom2) & ellipsis

    (* raccourci les noms LONGs affichŽs sous la forme

    "VeryVeryLongFileName#131B92.cwk"

    ¥ shortens LONG names displaid as

    ¥ "VeryVeryLongFileName#131B92.cwk" *)

     

    if nom2 contains Borne then

    set posiBorne to offset of Borne in nom2

    set debut to text 1 thru posiBorne of nom2

    set vieuxNum to text (posiBorne + 1) thru -1 of nom2

    try

    set nouveauNum to vieuxNum + 1

    (* gŽnre une erreur si ce qui suit borne n'est pas un nombre *)

    on error

    set nouveauNum to 1

    end try

    else

    if (count of nom2) > 22 then Â

    set nom2 to (text 1 thru 21 of nom2) & ellipsis

    (* pour rester dans la limite de 31 caractres

    ¥ to stay in the 31 characters range *)

    set debut to nom2 & Borne

    set nouveauNum to 1

    end if

     

    set nouveauChemin to my Â

    quelChemin(debut, nouveauNum, avecExtension, leDossier)

     

    tell front document

    save nom1 in nouveauChemin

     

    if not (laFamille = "") then

    tell application "Finder"

    activate

    try

    set label index of file nouveauChemin to laFamille

    end try

    end tell -- to Finder

    end if

    end tell -- to front

    end tell -- AppleWorks

     

    on error MsgErr number NroErr

    if NroErr is not -128 then

    beep 2

    tell application (path to frontmost application as string) to Â

    display dialog "" & NroErr & " : " & MsgErr with icon 0 Â

    buttons {msg99} giving up after 20

    end if

    set AppleScript's text item delimiters to vieuxDelim

    return

    end try

    end run

     

    -- ------------------------------------- Routines

     

    on quelChemin(leDebut, nouvoNum, avExtension, dossier)

    tell application "Finder"

    repeat

    set nouvoNom to Â

    leDebut & text -4 thru -1 of ("0000" & nouvoNum)

    if avExtension is true then Â

    set nouvoNom to nouvoNom & extension

    set nouvoChemin to "" & dossier & nouvoNom

    if exists file nouvoChemin then

    set nouvoNum to nouvoNum + 1

    else

    exit repeat

    end if

    end repeat

    end tell -- to Finder

    return nouvoChemin

    end quelChemin

     

    -- -------------------------------------

     

    on quelOS()

    tell application "Finder"

    set versionOS to version as text

    if "10." is in versionOS then

    set forX to true

    else

    set forX to false

    end if

    end tell

    return forX

    end quelOS

     

    -- -------------------------------------

     

    on prepareMessages()

    if french is true then

    set msg0 to "Ce script nÕest pas compatible" & return & Â

    "avec cette version dÕAppleWorks." & return & Â

    "Veuillez utiliser une version 6.x É"

    set msg1 to Â

    Â

    "Document crŽŽ par une ancienne version dÕAppleWorks." & return & "Il faudrait lÕenregistrer au format AW6."

    set msg2 to "Aucun document ouvert"

    set msg99 to "ÊVuÊ"

    else

    set msg0 to "This script is not compatible" & return & Â

    "with this version of AppleWorks." & return & Â

    "Please use version 6.x ..."

    set msg1 to Â

    Â

    "Document created with an old AppleWorks." & return & "Save it once as AW6."

    set msg2 to "No open document"

    set msg99 to "ÊOopsÊ"

    end if

    end prepareMessages

     

    -- [/SCRIPT]

     

  • by rrobelen,

    rrobelen rrobelen Dec 29, 2013 7:48 AM in response to rrobelen
    Level 1 (0 points)
    Dec 29, 2013 7:48 AM in response to rrobelen

    I checked all the file names in question.  None exceed 30 characters before the .cwk extension.  Those with the more elaborate endings listed still do not exceed the 30 characters before the .cwk. extension.  None should be truncated due to the 31 charater limit.

  • by rrobelen,

    rrobelen rrobelen Jan 1, 2014 3:35 PM in response to rrobelen
    Level 1 (0 points)
    Jan 1, 2014 3:35 PM in response to rrobelen

    I bit the bullet and resorted to an almost manual conversion of 238 cwk files. This was done using Appleworks 6 running on Snow Leopard.  I say almost manual because I did use Yvan Koenig’s Applescript ‘AW save As 6.applescript’ https://app.box.com/s/00qnssoyeq2xvc22ra4k/1/792761643 in my otherwise manual effort.  Here are the details for anyone in a similar boat.

    In Finder I used a filtered search on extension “cwk” to get all the cwk files in one long list in Finder.  I then batch opened 10 files at a time (the desktop gets full if you do many more).  They open in AW 6.  Next I ran the Applescript ‘AW save As 6.applescript’ (one click in the Applescript Editor I kept open off to the side). It converts the top file opened in AW 6 (the last of the 10) and saves it to its original location.  I then closed the file (one click).  One file converted.  Repeat by running ‘AW save As 6.applescript’ again.  This time the next to last file opened (the one now on the top) is converted and saved.  Close it. 

    I continued this two-step process through all 10 files and then repeated it until all 238 were converted.   It took maybe 40 minutes.  In Finder I set the view to show the ‘File creation date’.  As each file is converted its creation date changes to today.  This gives you feedback that the files are in fact being converted.  It’s easy to close the wrong one if you are not careful.

    I tried to modify Koenig’s ‘AW save AS 6’ to close the file after the save but could not get it to work.  This would have saved one of the manual steps.  Having spent way too much time already I just continued on with my two step. 

    The files that had their names changed to #XXXXX, as reported in my previous post, were files with names that exceeded 28 characters.  Fortunately there were only 14 of them and I just renamed them back to their original after the conversion.  I plan to write something in Excel VBA for the Mac to change the file creation date back to the original dates which I have saved.  Having the real creation date is helpful when trying to find something old. 

    Maybe there is a better way but this does work.

    Next step is to install iWorks 10 for Snow Leopard on Snow Leopard to eventually get the files into Pages and Numbers.  Stay tuned.

     

  • by fruhulda,

    fruhulda fruhulda Jan 1, 2014 9:44 PM in response to rrobelen
    Level 6 (15,126 points)
    Jan 1, 2014 9:44 PM in response to rrobelen

    There isn't any iWork 10. You have to do with iWork 09 which isn't bad to use. I rather like it but took a while to learn as it is behaving differently to AW.

  • by Hiroto,

    Hiroto Hiroto Jan 1, 2014 9:55 PM in response to rrobelen
    Level 5 (7,276 points)
    Jan 1, 2014 9:55 PM in response to rrobelen

    Hello

     

    Sorry for being late. It appears the Yvan's script is using document name to determine file name, which results in truncated name in some cases due to the said limitation of AppleWorks 6.

     

    Since your goal is to convert old AW/CW files to iWork'09 files, I guess you'll be using Yvan's batch_WPSS2iWork.applescript, which you can find at his public folder:

     

    Yvan Koenig's public folder:

    https://app.box.com/s/00qnssoyeq2xvc22ra4k

     

    > public_YK/for_iWork'09/other_iWork'09 items/batch_WPSS2iWork.zip

     

     

    This zip archive contains two applescripts – batch_AW6_2iWork.applescript and batch_AWx2iWork.applescript – and the latter is intended to convert old AW/CW files to iWork'09 files. However, this latter script is also using document name to determine file name in AW to AW6 conversion, which manifests the same problem as "AW save as 6.applescript" found at:

     

    > public_YK/Scripts_for_AppleWorks/AW save as 6.applescript.zip

     

     

    Although it is possible to modify those scripts so that they always preserve the original file name, here I've chosen to craft another script afresh, for it is easier for me. The script listed below will convert AppleWorks / ClarisWorks files prior to version 6 to AppleWorks 6 files. It implements two operation modes – in-place conversion (i.e., overwriting the original with the converted) and separate conversion (i.e., saving the converted as new file) – which you may specify as boolean value in script property in_place. See comments in script for more details.

     

    Once you have converted those old files to AW6 files, you may use Yvan's batch_AW6_2iWork.applescript to convert them to iWork'09 files. This script of Yvan's appears not to use document name to determine file name and thus should not yield truncated name.

     

    Regards,

    H

     

     

    -- save_AW_as_v6.applescript
    (*
        Convert files of AppleWorks / ClarisWorks prior to version 6 to AppleWorks 6 files.
        v0.1
        
        * Tested with AppleWorks 6.2.4 under OS X 10.6.8.
        * AppleWorks 6.2.9 may fail to open old ClarisWorks files, in which case use older version such as AppleWorks 6.2.4.
        * Specify property in_place in script, which defines the operation mode, as necessary.
        * A log file with time-stamp in name is created on desktop.
        * Original file name is always preserved.
            Name extension ".cwk" is not added in destination file if it is missing in source file.
            This is to avoid possible data loss in case there're file names, e.g., abc and abc.cwk in a source directory.
    *)
    _main()
    on _main()
        script o
            property in_place : false
            (*
                true : convert files in place, i.e. files are overwritten, 
                    where original source directory is archived in zip file with time-stamp in name in advance;
                false : converted files are saved in destination directory which is specified in a dialogue in script
            *)
            property logfile : (path to desktop)'s POSIX path & (do shell script "date +'save_AW_as_v6.log_%Y%m%dT%H%M%S.txt'")
            property pp : {}
            
            -- accept source directory (and destination direcotry if in_place is false)
            set srcd to (choose folder with prompt "Choose source directory where source files reside.")'s POSIX path
            if srcd ends with "/" and (count srcd) > 1 then set srcd to srcd's text 1 thru -2
            if not in_place then
                repeat
                    set dstd to (choose folder with prompt "Choose destination directory where to save converted files.")'s POSIX path
                    if dstd ends with "/" and (count dstd) > 1 then set dstd to dstd's text 1 thru -2
                    if srcd ≠ dstd then exit repeat
                    display dialog "Source and destination directories cannot be the same!" with icon stop
                end repeat
            end if
            log_printf(logfile, "conversion started in operation mode: in_place = %s.\\n", in_place)
            
            -- retrieve target files
            log_printf(logfile, "scanning files under %s\\n", srcd)
            set pp to _match(my is_AW_but_v6, scan_AW_files(srcd))
            log_printf(logfile, "found %d file(s) to process.\\n", count my pp)
            
            -- process target files
            if (count my pp) > 0 then
                if in_place then
                    -- archive the source directory first (zip file name = srcd_YYYY-MM-DDTHH.MM.SS.zip)
                    set dst to do shell script "src=" & srcd's quoted form & "
    dst=\"${src}_$(date +'%FT%H.%M.%S').zip\"
    ditto -ck --keepParent --sequesterRsrc \"$src\" \"$dst\"
    echo \"$dst\""
                    log_printf(logfile, "source directory is archived in %s\\n", dst)
                    repeat with p in my pp
                        set p to p's contents
                        save_AW_as_v6(p, p)
                        log_printf(logfile, "converted %s\\n", p)
                    end repeat
                else
                    set slen to count srcd
                    repeat with p in my pp
                        set p to p's contents
                        set q to dstd & (p's text (slen + 1) thru -1)
                        save_AW_as_v6(p, q)
                        log_printf(logfile, "converted %s  =>  %s\\n", {p, q})
                    end repeat
                end if
            end if
            
            -- completion notice
            log_printf(logfile, "process completed for total of %d file(s).\\n", count my pp)
            tell me
                activate
                display dialog "Done " & (count my pp) & " file(s)." giving up after 5 with icon note
            end tell
        end script
        tell o to run
    end _main
    
    on scan_AW_files(d)
        (*
            string d : POSIX path of source directory where to start scanning
            return list : list of POSIX paths of found files
            
            * query condition is (file name extension = "cwk") OR (file creator type = "BOBO")
        *)
        script o
            property pp : {}
            property qq : {}
            property rr : {}
            
            tell application "System Events"
                tell disk item d
                    set pp to every folder's POSIX path
                    repeat with p in my pp
                        set qq to my scan_AW_files(p's contents)
                        repeat with q in my qq
                            set end of my rr to q's contents
                        end repeat
                    end repeat
                    set qq to every file's POSIX path whose name extension = "cwk" or creator type = "BOBO"
                    repeat with q in my qq
                        set end of my rr to q's contents
                    end repeat
                end tell
            end tell
            return my rr's contents
        end script
        tell o to run
    end scan_AW_files
    
    on is_AW_but_v6(f)
        (*
            string f : POSIX path of source file
            return boolean : true if f is AW/CW file of version prior to 6, false otherwise
            
            * matching codition is (byte 1 < 0x06) AND (bytes 5..8 = 'BOBO')
        *)
        set f to f as POSIX file --as alias
        --return (read f from 5 for 4)'s id = {66, 79, 66, 79} and (read f for 1)'s id < 6 -- for 10.5 or later only
        considering case
            return (read f from 5 for 4) = "BOBO" and (ASCII number (read f for 1)) < 6
        end considering
    end is_AW_but_v6
    
    on save_AW_as_v6(src, dst)
        (*
            string src : POSIX path of source file, typically file of AW5 or CW4 etc
            string dst : POSIX path of destination file
            
            * src may equate to dst, in which case src is overwritten
            * intermeditate directories in dst will be created as needed if not present
        *)
        -- get source alias
        set srca to src as POSIX file as alias
        
        -- create temp file
        set tmp to do shell script "mktemp /tmp/save_AW_as_v6.XXXXXXXX"
        set tmpa to tmp as POSIX file as alias
        
        -- convert to AW6 and save in temp file
        tell application "AppleWorks 6"
            activate
            set k to count documents
            open srca
            repeat until (count documents) > k
                delay 0.2
            end repeat
            tell document 1
                close saving in tmpa
            end tell
        end tell
        
        -- wait for the temp file is closed
        wait_file_close(tmp)
        
        -- set label of temp file to label of source file -- [1]
        repeat 3 times -- max retry
            try -- [2]
                tell application "Finder"
                    set lbl to item srca's label index
                    tell item tmpa
                        update
                        set its label index to lbl
                    end tell
                end tell
                exit repeat -- exit if no error
                delay 0.5 -- wait some time before retry
            end try
        end repeat
        
        -- move temp file to destination file (destination directory tree is created as necessary)
        do shell script "tmp=" & tmp's quoted form & "; dst=" & dst's quoted form & "
    d=${dst%/*}; [[ -d \"$d\" ]] || mkdir -p \"$d\"
    mv -f \"$tmp\" \"$dst\""
        
        (*
            [1] This is required because AW6 does not preserve the original label when saving file.
            [2] Finder is such an unreliable beast that it may fail even after the file is indeed closed.
        *)
    end save_AW_as_v6
    
    on wait_file_close(f)
        (*
            string f : POSIX path of file
            
            * wait until f is no longer opened by AppleWorks
        *)
        do shell script "f=" & f's quoted form & "
    while [[ $(lsof -Fc \"$f\") =~ 'AppleWorks' ]]; do sleep 0.3; done"
    end wait_file_close
    
    on _match(pat, aa)
        (*
            handler pat : handler to test elements in aa
            list aa : source list
            return list : list of every element a of list aa whose pat(a) = true
        *)
        script o
            property |::xx| : aa's contents
            property |::yy| : {}
            property |::f| : pat
            repeat with x in my |::xx|
                set x to x's contents
                if my |::f|(x) then set end of my |::yy| to x
            end repeat
            return my |::yy|'s contents
        end script
        tell o to run
    end _match
    
    on log_printf(f, fmt, lst)
        (*
            string f : POSIX path of log file
            string fmt : printf format string
            list lst : list of values (if lst is one item list {x}, lst may be x)
            
            * %-26s time-stamp in format %F %T%z is added to the beginning of each entry
        *)
        local args
        set args to "'%-26s'" & fmt's quoted form & " \"$(date +'%F %T%z')\" "
        repeat with a in {} & lst
            set args to args & (a as string)'s quoted form & space
        end repeat
        do shell script "printf " & args & " >> " & f's quoted form
    end log_printf
    
  • by Hiroto,

    Hiroto Hiroto Jan 1, 2014 10:40 PM in response to rrobelen
    Level 5 (7,276 points)
    Jan 1, 2014 10:40 PM in response to rrobelen

    Hello

     

    Here's a revised version to implement an optional function to  inherit the creation and modification dates of source files. Specify the boolean property inherit_dates as needed.

     

    Regards,

    H

     

    -- save_AW_as_v6.applescript
    (*
        Convert files of AppleWorks / ClarisWorks prior to version 6 to AppleWorks 6 files.
        v0.2
    
        v0.2 -
            added optional function to inherit creation and modification dates of source files
    
        * Tested with AppleWorks 6.2.4 under OS X 10.6.8.
        * AppleWorks 6.2.9 may fail to open old ClarisWorks files, in which case use older version such as AppleWorks 6.2.4.
        * Specify property in_place in script as necessary.
        * Specify property inherit_dates in script as necessary.
        * A log file with time-stamp in name is created on desktop.
        * Original file name is always preserved.
            Name extension ".cwk" is not added in destination file if it is missing in source file.
            This is to avoid possible data loss in case there're file names, e.g., abc and abc.cwk in a source directory.
    *)
    _main()
    on _main()
        script o
            property in_place : false
            (*
                true : convert files in place, i.e. files are overwritten, 
                    where original source directory is archived in zip file with time-stamp in name in advance;
                false : converted files are saved in destination directory which is specified in a dialogue in script
            *)
            property inherit_dates : true
            (*
                true : destination file inherits creation date and modification date of source file
                false : destination file has creation date and modification date at the time of conversion
            *)
            property logfile : (path to desktop)'s POSIX path & (do shell script "date +'save_AW_as_v6.log_%Y%m%dT%H%M%S.txt'")
            property pp : {}
    
            -- accept source directory (and destination direcotry if in_place is false)
            set srcd to (choose folder with prompt "Choose source directory where source files reside.")'s POSIX path
            if srcd ends with "/" and (count srcd) > 1 then set srcd to srcd's text 1 thru -2
            if not in_place then
                repeat
                    set dstd to (choose folder with prompt "Choose destination directory where to save converted files.")'s POSIX path
                    if dstd ends with "/" and (count dstd) > 1 then set dstd to dstd's text 1 thru -2
                    if srcd ≠ dstd then exit repeat
                    display dialog "Source and destination directories cannot be the same!" with icon stop
                end repeat
            end if
            log_printf(logfile, "conversion started in operation mode: in_place = %s, inherit_dates = %s.\\n", {in_place, inherit_dates})
    
            -- retrieve target files
            log_printf(logfile, "scanning files under %s\\n", srcd)
            set pp to _match(my is_AW_but_v6, scan_AW_files(srcd))
            log_printf(logfile, "found %d file(s) to process.\\n", count my pp)
    
            -- process target files
            if (count my pp) > 0 then
                if in_place then
                    -- archive the source directory first (zip file name = srcd_YYYY-MM-DDTHH.MM.SS.zip)
                    set dst to do shell script "src=" & srcd's quoted form & "
    dst=\"${src}_$(date +'%FT%H.%M.%S').zip\"
    ditto -ck --keepParent --sequesterRsrc \"$src\" \"$dst\"
    echo \"$dst\""
                    log_printf(logfile, "source directory is archived in %s\\n", dst)
                    repeat with p in my pp
                        set p to p's contents
                        save_AW_as_v6(p, p, {inherit_dates:inherit_dates})
                        log_printf(logfile, "converted %s\\n", p)
                    end repeat
                else
                    set slen to count srcd
                    repeat with p in my pp
                        set p to p's contents
                        set q to dstd & (p's text (slen + 1) thru -1)
                        save_AW_as_v6(p, q, {inherit_dates:inherit_dates})
                        log_printf(logfile, "converted %s  =>  %s\\n", {p, q})
                    end repeat
                end if
            end if
    
            -- completion notice
            log_printf(logfile, "process completed for total of %d file(s).\\n", count my pp)
            tell me
                activate
                display dialog "Done " & (count my pp) & " file(s)." giving up after 5 with icon note
            end tell
        end script
        tell o to run
    end _main
    
    on scan_AW_files(d)
        (*
            string d : POSIX path of source directory where to start scanning
            return list : list of POSIX paths of found files
    
            * query condition is (file name extension = "cwk") OR (file creator type = "BOBO")
        *)
        script o
            property pp : {}
            property qq : {}
            property rr : {}
    
            tell application "System Events"
                tell disk item d
                    set pp to every folder's POSIX path
                    repeat with p in my pp
                        set qq to my scan_AW_files(p's contents)
                        repeat with q in my qq
                            set end of my rr to q's contents
                        end repeat
                    end repeat
                    set qq to every file's POSIX path whose name extension = "cwk" or creator type = "BOBO"
                    repeat with q in my qq
                        set end of my rr to q's contents
                    end repeat
                end tell
            end tell
            return my rr's contents
        end script
        tell o to run
    end scan_AW_files
    
    on is_AW_but_v6(f)
        (*
            string f : POSIX path of source file
            return boolean : true if f is AW/CW file of version prior to 6, false otherwise
    
            * matching codition is (byte 1 < 0x06) AND (bytes 5..8 = 'BOBO')
        *)
        set f to f as POSIX file --as alias
        --return (read f from 5 for 4)'s id = {66, 79, 66, 79} and (read f for 1)'s id < 6 -- for 10.5 or later only
        considering case
            return (read f from 5 for 4) = "BOBO" and (ASCII number (read f for 1)) < 6
        end considering
    end is_AW_but_v6
    
    on save_AW_as_v6(src, dst, {inherit_dates:inherit_dates})
        (*
            string src : POSIX path of source file, typically file of AW5 or CW4 etc
            string dst : POSIX path of destination file
            boolean inherit_dates: true for dst to inherit creation and modification dates of src, false otherwise.
    
            * src may equate to dst, in which case src is overwritten
            * intermeditate directories in dst will be created as needed if not present
        *)
        -- get source alias
        set srca to src as POSIX file as alias
    
        -- create temp file
        set tmp to do shell script "mktemp /tmp/save_AW_as_v6.XXXXXXXX"
        set tmpa to tmp as POSIX file as alias
    
        -- convert to AW6 and save in temp file
        tell application "AppleWorks 6"
            activate
            set k to count documents
            open srca
            repeat until (count documents) > k
                delay 0.2
            end repeat
            tell document 1
                close saving in tmpa
            end tell
        end tell
    
        -- wait for the temp file is closed
        wait_file_close(tmp)
    
        -- set label of temp file to label of source file -- [1]
        repeat 3 times -- max retry
            try -- [2]
                tell application "Finder"
                    set lbl to item srca's label index
                    tell item tmpa
                        update
                        set its label index to lbl
                    end tell
                end tell
                exit repeat -- exit if no error
                delay 0.5 -- wait some time before retry
            end try
        end repeat
    
        -- inherit creation and modication dates from src to tmp
        if inherit_dates then inherit_file_dates(src, tmp)
    
        -- move temp file to destination file (destination directory tree is created as necessary)
        do shell script "tmp=" & tmp's quoted form & "; dst=" & dst's quoted form & "
    d=${dst%/*}; [[ -d \"$d\" ]] || mkdir -p \"$d\"
    mv -f \"$tmp\" \"$dst\""
    
        (*
            [1] This is required because AW6 does not preserve the original label when saving file.
            [2] Finder is such an unreliable beast that it may fail even after the file is indeed closed.
        *)
    end save_AW_as_v6
    
    on wait_file_close(f)
        (*
            string f : POSIX path of file
    
            * wait until f is no longer opened by AppleWorks
        *)
        do shell script "f=" & f's quoted form & "
    while [[ $(lsof -Fc \"$f\") =~ 'AppleWorks' ]]; do sleep 0.3; done"
    end wait_file_close
    
    on _match(pat, aa)
        (*
            handler pat : handler to test elements in aa
            list aa : source list
            return list : list of every element a of list aa whose pat(a) = true
        *)
        script o
            property |::xx| : aa's contents
            property |::yy| : {}
            property |::f| : pat
            repeat with x in my |::xx|
                set x to x's contents
                if my |::f|(x) then set end of my |::yy| to x
            end repeat
            return my |::yy|'s contents
        end script
        tell o to run
    end _match
    
    on log_printf(f, fmt, lst)
        (*
            string f : POSIX path of log file
            string fmt : printf format string
            list lst : list of values (if lst is one item list {x}, lst may be x)
    
            * %-26s time-stamp in format %F %T%z is added to the beginning of each entry
        *)
        local args
        set args to "'%-26s'" & fmt's quoted form & " \"$(date +'%F %T%z')\" "
        repeat with a in {} & lst
            set args to args & (a as string)'s quoted form & space
        end repeat
        do shell script "printf " & args & " >> " & f's quoted form
    end log_printf
    
    on inherit_file_dates(src, dst)
        (*
            string src : POSIX path of source file
            string dst : POSIX path of destination file
    
            * If creation date of src is older than or equal to that of dst,
                this will set both creation date and modification date of dst to those of src.
            * If creation date of src is newer than that of dst,
                this will set only modification date of dst to that of src.
        *)
        do shell script "src=" & src's quoted form & "; dst=" & dst's quoted form & "
    ct=$(stat -f '%SB' -t '%Y%m%d%H%M.%S' \"$src\")
    mt=$(stat -f '%Sm' -t '%Y%m%d%H%M.%S' \"$src\")
    touch -t $ct \"$dst\"    # set creation date (<= current creation date)
    touch -mt $mt \"$dst\"    # set modification date (>= creation date)"
    end inherit_file_dates
    
  • by rrobelen,

    rrobelen rrobelen Jan 2, 2014 4:56 AM in response to fruhulda
    Level 1 (0 points)
    Jan 2, 2014 4:56 AM in response to fruhulda

    This is a reply to fruhulda.

    Thank you for your reply.  I meant to say I was going to use iWork 09 instead of 10.  I have not gotten to that phase and forgot that it was 09 that i ordered from Amazon.  Thanks again for pointing that out.

    Regards,

    Russ

     

    Message was edited by: rrobelen

  • by rrobelen,

    rrobelen rrobelen Jan 2, 2014 11:57 AM in response to rrobelen
    Level 1 (0 points)
    Jan 2, 2014 11:57 AM in response to rrobelen

    this is a reply to Hiroto

    Hiroto,

    First many many thanks for taking the time to write the scripts you sent me.  If I understand your reply correctly the first script would replace the manual operation I described that I used to convert the 238 (actually the total was 245) cwk files that were created prior to AW 6.  The second script would do the same but also preserve the original file name and creation date. I like that original file creation date is preserved.  This will save me writing VBA code to do the same.

    Looking at the script it appears to me that the code assumes the source folder I choose has cwk files as well as subfolders that also contain cwk files.  The script will find and convert all of them.  I set ‘property in place’ to true and ‘property inherit_dates’ to true, compiled and ran the code.  The folder I choose had one cwk file and many subfolders with cwk files.  The script did not convert any files.  The message said “Done 0 files(s)”.  The log text file said the same thing, no files converted. I tried it again choosing a folder that contained 3 cwk files and no subfolders.  The results were the same. Your ‘Save_AW_as_V6.log… ‘ read as follows:

    2014-01-02 10:19:36-0500  conversion started in operation mode: in_place = false, inherit_dates = true.

    2014-01-02 10:19:36-0500  scanning files under folder name selected – I deleted actual folder name here

    2014-01-02 10:19:37-0500  found 0 file(s) to process.

    2014-01-02 10:19:37-0500  process completed for total of 0 file(s).

    I am running your script on a Mac running 10.6.8 (same as your test bed).  The Mac has AW 6.2.7 (you are using 6.2.4).  A few days ago I tried installing Xcode 3 so I could see what is going on with script.  I could not get it to work to where I could single step script and observe what is happening.  I am using the primitive script editor which has no single cycle capability so it is not easy to follow your script to see the operations and where I might be misinterpreting how it is supposed to work. 

    To try and gain some insight I ran Yvan’s script ‘batch_AWx2iWork’.  Once on a small number of cwk files it ran to completion converting some files to pages and numbers but leaving others unconverted.  I didn’t see anything about the cwk files uncoverted (length of file names is not an issue) that looks different.  On another sample I got a number of illegal file name messages in the report.  On a couple of others trying to convert the entire set I get messages that numbers has failed and a report is being sent to Apple. 

    I really would like to use what you have sent me if I can get it to work.  In Yvan’s script he notes the following: Alas, the script can't recover cases where Numbers or Pages freeze during an import process. Reboot is the unique emergency issue available. Is this a common problem?  I am doing all this using remote control (LogMein) on the remote Mac.  So far it is working ok but if I have to reboot it will be an issue.

    Do you have any suggestions given what I have told you?

    Regards,

    Russ

  • by rrobelen,

    rrobelen rrobelen Jan 2, 2014 2:28 PM in response to rrobelen
    Level 1 (0 points)
    Jan 2, 2014 2:28 PM in response to rrobelen

    This is not to the people here who have been helping me.  I really appreciate their help.  This is a general rant.

     

    I took one of the cwk files that was created in some earlier version of AppleWorks or ClarisWorks.  I can’t tell which other than the date the file was created probably would get me close.  I suspect it was a Claris Works file.  Taking this file through a conversion to AW 6 on a Mac running Snow Leopard and then a conversion to iWorks 09 running on SL and finally to Pages 3.0.3 on a Mac running Mountain Lion , I am very disappointed with what I end up with.  So much of the formatting is lost.  Bold type is completely gone.   But it is in Pages the preferred word processor for Apple.

    When I open the same file in LibreOffice 4.1 it opens with the proper formatting and bold type is there just like the original.  After all this work I would be better off convincing the user to switch to LibreOffice.  Its free and creating and editing is not that much different form Pages for simple documents. 

    To make matters worse I have read on several forums concerns that Pages may not be staying around much longer.  Another conversion may loom in the future.  I don’t know whether this is just user grumbling or it has substance.  I have to see this through to the end for the spreadsheets as there is no other alternative (at least that I know of).  I am not a happy camper.

     

  • by Hiroto,

    Hiroto Hiroto Jan 2, 2014 9:57 PM in response to rrobelen
    Level 5 (7,276 points)
    Jan 2, 2014 9:57 PM in response to rrobelen

    Hello

     

    Both scripts of mine – save_AW_as_v6.applescript v0.1 and v0.2 – will preserve the original file names. The v0.2 script can inherit creation and modification dates of source files according to boolean value set in the property inherit_dates in script.

     

    Both scripts only process files of AppleWorks or ClarisWorks version 5 or earlier. Any files in AppleWorks version 6 format are ignored. I'd guess this is the reason you see no files found in your target directory. Check whether they're really files prior to version 6, for instance, by opening it in AppleWorks 6 manually and then closing the document without edit, which should present a save dialogue if the original file is of old version.

     

    ---

    In case for debugging, the following scriptlet consists of relevant parts to retrieve pre-AW6 files. It will scan files under ~/Desktop/test and should return {AW file count, pre-AW6 file count, AW files, pre-AW6 files}.

     

    --scanning test
    set d to (path to desktop)'s POSIX path & "test"
    set ff to scan_AW_files(d)
    set ff1 to _match(is_AW_but_v6, ff)
    return {count ff, count ff1, ff, ff1}
    
    on scan_AW_files(d)
        (*
            string d : POSIX path of source directory where to start scanning
            return list : list of POSIX paths of found files
        *)
        script o
            property pp : {}
            property qq : {}
            property rr : {}
    
            tell application "System Events"
                tell disk item d
                    set pp to every folder's POSIX path
                    repeat with p in my pp
                        set qq to my scan_AW_files(p's contents)
                        repeat with q in my qq
                            set end of my rr to q's contents
                        end repeat
                    end repeat
                    set qq to every file's POSIX path whose name extension = "cwk" or creator type = "BOBO"
                    repeat with q in my qq
                        set end of my rr to q's contents
                    end repeat
                end tell
            end tell
            return my rr's contents
        end script
        tell o to run
    end scan_AW_files
    
    on is_AW_but_v6(f)
        (*
            string f : POSIX path of source file
            return boolean : true if f is AW/CW file of version prior to 6, false otherwise
        *)
        set f to f as POSIX file
        --return (read f from 5 for 4)'s id = {66, 79, 66, 79} and (read f for 1)'s id < 6 -- for 10.5 or later only
        considering case
            return (read f from 5 for 4) = "BOBO" and (ASCII number (read f for 1)) < 6
        end considering
    end is_AW_but_v6
    
    on _match(pat, aa)
        (*
            handler pat : handler to test elements in aa
            list aa : source list
            return list : list of every element a of list aa whose pat(a) = true
        *)
        script o
            property |::xx| : aa's contents
            property |::yy| : {}
            property |::f| : pat
            repeat with x in my |::xx|
                set x to x's contents
                if my |::f|(x) then set end of my |::yy| to x
            end repeat
            return my |::yy|'s contents
        end script
        tell o to run
    end _match
    

     

    Hope this helps,

    H

first Previous Page 3 of 5 last Next