Get File Type/Creator?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Get File Type/Creator?
Hm, sorry, no brilliant idea in the moment...
Re: Get File Type/Creator?
In the loadfile handler, the first line:
will put the contents of the file into the field. All you want is the file name itself:
Code: Select all
put URL ("file:" & pFileName) into field "Display"
Code: Select all
put pFileName into field "Display"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Get File Type/Creator?
Good catch, but that does not solve his mistery. 

Re: Get File Type/Creator?
Hi Jacque,
Did I do something wrong?
I do need to put the contents of the file into the field. From there, I can have LC search the contents for a particular text string. Ultimately, my plan is to put the contents into a variable (which I hope will be faster).
Thank you,
Jon
Did I do something wrong?
I do need to put the contents of the file into the field. From there, I can have LC search the contents for a particular text string. Ultimately, my plan is to put the contents into a variable (which I hope will be faster).
Thank you,
Jon
Re: Get File Type/Creator?
No, I understand now. Have you examined a file in a text editor to be sure it does actually contain the string you're looking for? I don't use InDesign so I can't look myself.
As far as an empty field, binary files contain invisible characters that may appear at the front of the file and the field would appear to be empty. You're loading the file in as text rather than binary though, so it's likely the entire content has been changed anyway (assuming the file is binary to begin with.) For a binary file, you need to use ("binfile:" & pFileName).
After the handler places the file content into the field, check to see if the field is really empty from the message box. If so, then add some error checking:
Code: Select all
get URL ("binfile:" & pFileName)
answer (it is empty) && the result
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Get File Type/Creator?
Hi Jacque,
Yes, I have examined the InDesign file and the string I am looking for IS in there. It seems that no matter what I do, I get the "Not Found." dialog box before the text appears in the text field.
It seems like I need some sort of break (as if the app were idle) in between commands because the text field is not populated until the script has finished executing (which occurs after I click OK to the "Not Found." dialog box). I've tried moving the loadFile and subsequent field check into separate handers (on loadFile and on checkFile) but I get the same result.
Jon
Yes, I have examined the InDesign file and the string I am looking for IS in there. It seems that no matter what I do, I get the "Not Found." dialog box before the text appears in the text field.
It seems like I need some sort of break (as if the app were idle) in between commands because the text field is not populated until the script has finished executing (which occurs after I click OK to the "Not Found." dialog box). I've tried moving the loadFile and subsequent field check into separate handers (on loadFile and on checkFile) but I get the same result.
Jon
Re: Get File Type/Creator?
I understand a little more with every new post.
If I've got it right now, the launch fails on startup but works if the app is already open. If so, the problem is in the startup handler, which you should remove entirely if your target is Mac OS X only.
The environment variable $1 only has a value if the app is launched by the command line (i.e., Terminal) on Mac. In my experience it is always empty on a normal desktop launch. What I think is happening is that the startup handler tries to launch an empty filename, which is why you see nothing in the field. The search string is obviously missing and you get "not found". The loadfile handler finishes after you dismiss the dialog, and the now-queued appleEvent takes over. Since that does provide file content, you see the newly-loaded file in the field.
If you do want to use the app on Windows, leave the startup handler in place but don't call the loadfile handler unless the platform is "win32", where the environment variable should have the value you expect. On Mac, the AppleEvent should trigger instead.
I hope this doesn't take you off on a goose chase again, I didn't actually try to build an app with the script.

The environment variable $1 only has a value if the app is launched by the command line (i.e., Terminal) on Mac. In my experience it is always empty on a normal desktop launch. What I think is happening is that the startup handler tries to launch an empty filename, which is why you see nothing in the field. The search string is obviously missing and you get "not found". The loadfile handler finishes after you dismiss the dialog, and the now-queued appleEvent takes over. Since that does provide file content, you see the newly-loaded file in the field.
If you do want to use the app on Windows, leave the startup handler in place but don't call the loadfile handler unless the platform is "win32", where the environment variable should have the value you expect. On Mac, the AppleEvent should trigger instead.
I hope this doesn't take you off on a goose chase again, I didn't actually try to build an app with the script.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Get File Type/Creator?
I got it working now! 
Thanks,
Jon

Thanks,
Jon
Re: Get File Type/Creator?
Hi everyone,
I have my app pretty much working. I would like to add support for QuarkXPress files however, when opening a Quark file with a text editor, virtually all the content within is gibberish. I assume this is intended by the software developer. So here's my question as I am not certain of the proper terminology but with the content being in all gibberish, does this mean the contents of the file are encrypted or somehow encoded?
Please correct me if I am using the wrong terminology. Regardless of terminology though, is there a way to somehow convert/decrypt/decode the content into something that is readable?
Thanks,
Jon
I have my app pretty much working. I would like to add support for QuarkXPress files however, when opening a Quark file with a text editor, virtually all the content within is gibberish. I assume this is intended by the software developer. So here's my question as I am not certain of the proper terminology but with the content being in all gibberish, does this mean the contents of the file are encrypted or somehow encoded?
Please correct me if I am using the wrong terminology. Regardless of terminology though, is there a way to somehow convert/decrypt/decode the content into something that is readable?
Thanks,
Jon

-
- VIP Livecode Opensource Backer
- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Get File Type/Creator?
If it's total gibberish it may be another Zip based format - see my earlier post above on exploring this.
If not Zip based a quick web search may lead you to a description of the file format.
If not Zip based a quick web search may lead you to a description of the file format.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Get File Type/Creator?
Hi FourthWorld,
I tried your suggestion. Double-clicking the zip file yields a .cpgz file. If I double-click that, I get another zip file which then leads to another .cpgz file when double-clicked.
Not sure what that means but I am guessing that means it's not in a zip format?
Thank you,
Jon
I tried your suggestion. Double-clicking the zip file yields a .cpgz file. If I double-click that, I get another zip file which then leads to another .cpgz file when double-clicked.
Not sure what that means but I am guessing that means it's not in a zip format?
Thank you,
Jon

-
- Livecode Opensource Backer
- Posts: 10096
- Joined: Fri Feb 19, 2010 10:17 am
Re: Get File Type/Creator?
Well, all that "gibberish" is text to tell Quark Express how to interpret the "meat" of the file.virtually all the content within is gibberish
A little while ago I made a stack to import SVG files authored in Inkscape into a LiveCode SVG widget.
This actually prove fairly easy as "all" I had to do was open the file as text and strip out the "gibberish".
Your case is a bit more problematic as no-one has gone to all the trouble to author
a Quark Express File Widget for you to import the "meat" into.
I would start by opening a representative file in Quark Express and LOOKING at the thing to see what DATA it contains and HOW it is laid out.
As Quark Express IS a WYSIWYG webpage authoring system you "might" make life
a million times easier by simply exporting from QX to html and then loading
the html into LiveCode.
-
- Posts: 683
- Joined: Wed Apr 24, 2013 4:53 pm
- Contact:
Re: Get File Type/Creator?
I know this thread is ancient now but several things to note...
Doesn't 'detailed files' that include creator/type codes in the output on macOS LC engine?
If not then:
On macOS you could always use AppleScript like:
in conjunction with AppleScripts syntax for getting creator/type info from a file,
or use a bash script that gets all of a files extended-file-attributes (not just creator type)
Also, macOS BigSur and newer no longer supports HFS+ volumes, which means no legacy 'resource forks', but certain things like creator/type code have been retained, but now they're part of extended attributes of a file only. They can still be gotten and they can still be set, even on the latest macOS ('Sonoma' at the moment). So for anyone (like me) who still wants to be able to get and set those legacy creator codes I added a handler to my Extension builder library, you can get it here: https://github.com/PaulMcClernan/OpenXT ... App-Tools/ and see the LCB source code for that specific part of it here:
https://github.com/PaulMcClernan/OpenXT ... s.lcb#L456
Doesn't 'detailed files' that include creator/type codes in the output on macOS LC engine?
If not then:
On macOS you could always use AppleScript like:
Code: Select all
do tMyAppleScriptContainer as AppleScript
or use a bash script that gets all of a files extended-file-attributes (not just creator type)
Also, macOS BigSur and newer no longer supports HFS+ volumes, which means no legacy 'resource forks', but certain things like creator/type code have been retained, but now they're part of extended attributes of a file only. They can still be gotten and they can still be set, even on the latest macOS ('Sonoma' at the moment). So for anyone (like me) who still wants to be able to get and set those legacy creator codes I added a handler to my Extension builder library, you can get it here: https://github.com/PaulMcClernan/OpenXT ... App-Tools/ and see the LCB source code for that specific part of it here:
https://github.com/PaulMcClernan/OpenXT ... s.lcb#L456