Results 1 to 5 of 5

Thread: Problem with importing text files via applescript

  1. #1

    Default Problem with importing text files via applescript

    I've just downloaded EagleFiler and have been playing around a bit with CLI imports using applescript. I'm sure that this is a problem with my understanding of how the mac os encodes file meta data. Anyway, her goes.

    I tried this:
    created testimport.as in emacs based on the example in the manual:
    tell application "EagleFiler"
    tell library document 1
    import files {POSIX file "/Users/souheil/testimport.as"}
    end tell
    end tell

    Executed the script from the command line:
    osascript testimport.as
    This should import the script as a text file. Unfortunately, I get the "Unsupported File Type" error.

    Here's where I've gotten to in my debugging process:
    1) the file command returns:
    testimport.as.txt: ASCII Java program text
    2) the finder has no idea what the file type is
    3) if I make the extension .txt everything works as expected and the import goes smoothly
    4) The GUI does the same thing as the applescript. I suppose I should say that the applescript does the same thing as the GUI :-)

    I have a lot of test files with funny extensions, like .tex, .cls, .sty, .m, .c, .h, etc. (you guessed it, I'm a science geek), and I would like to import them into EagleFiler. Appending .txt to all the filename breaks a lot of other stuff. What should I do?

    Thanks,
    Souheil

  2. #2

    Default

    Quote Originally Posted by souheil View Post
    I have a lot of test files with funny extensions, like .tex, .cls, .sty, .m, .c, .h, etc. (you guessed it, I'm a science geek), and I would like to import them into EagleFiler. Appending .txt to all the filename breaks a lot of other stuff. What should I do?
    At present, EagleFiler identifies text files by:

    • Checking if the extension is one that the OS knows goes with text files. I think the OS knows about .h, .m, and .c files. It probably doesn't know about the TeX types unless you have an application installed that declares those types as text.
    • Checking if the HFS file type is one that the OS knows goes with text files.
    • Checking if the file starts with a byte order mark (BOM).


    My guess is that TeX wouldn't like it if you added BOMs to its files. I think the best bet, with EagleFiler 1.0.2, would be to set the types of the files to 'TEXT' so that EagleFiler and the OS know they're text. Going forward, I plan to make EagleFiler recognize more extensions and do more sniffing of file contents to identify text files.

  3. #3

    Default

    Okay that makes sense.

    A few more questions:
    • how do I set the type of the file to 'TEXT'?
    • is this an HFS+ only feature or will it work on NFS filesystems as well?


    Quote Originally Posted by Michael Tsai View Post
    At present, EagleFiler identifies text files by:

    • Checking if the extension is one that the OS knows goes with text files. I think the OS knows about .h, .m, and .c files. It probably doesn't know about the TeX types unless you have an application installed that declares those types as text.
    • Checking if the HFS file type is one that the OS knows goes with text files.
    • Checking if the file starts with a byte order mark (BOM).


    My guess is that TeX wouldn't like it if you added BOMs to its files. I think the best bet, with EagleFiler 1.0.2, would be to set the types of the files to 'TEXT' so that EagleFiler and the OS know they're text. Going forward, I plan to make EagleFiler recognize more extensions and do more sniffing of file contents to identify text files.

  4. #4

    Default

    Quote Originally Posted by souheil View Post
    • how do I set the type of the file to 'TEXT'?
    • is this an HFS+ only feature or will it work on NFS filesystems as well?
    There are various file utilities like Super Get Info, XRay, and File Buddy. There's the SetFile command that comes with the developer tools. Or you could save this AppleScript:

    Code:
    on open theFiles
        tell application "Finder"
            repeat with theFile in theFiles
                set file type of theFile to "TEXT"
            end repeat
        end tell
    end open
    as an application and use it as a droplet. File types are only natively stored on HFS, but OS X will emulate them on other file systems.

  5. #5

    Default

    Quote Originally Posted by souheil View Post
    I have a lot of test files with funny extensions, like .tex, .cls, .sty, .m, .c, .h, etc. (you guessed it, I'm a science geek), and I would like to import them into EagleFiler.
    EagleFiler 1.1 will look at the contents of files to try to recognize them as text, even if they don't have a known extension or HFS file type.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •