Get File Type/Creator?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: heatherlaine, Klaus, FourthWorld, kevinmiller

Klaus
Posts: 10110
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Get File Type/Creator?

Post by Klaus » Fri Dec 15, 2017 3:00 pm

Hm, sorry, no brilliant idea in the moment...

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4454
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Get File Type/Creator?

Post by jacque » Fri Dec 15, 2017 5:27 pm

In the loadfile handler, the first line:

Code: Select all

put URL ("file:" & pFileName) into field "Display"
will put the contents of the file into the field. All you want is the file name itself:

Code: Select all

put pFileName into field "Display"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 10110
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Get File Type/Creator?

Post by Klaus » Fri Dec 15, 2017 5:40 pm

Good catch, but that does not solve his mistery. :D

cmhjon
Posts: 43
Joined: Tue Aug 04, 2015 11:55 am

Re: Get File Type/Creator?

Post by cmhjon » Fri Dec 15, 2017 6:10 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4454
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Get File Type/Creator?

Post by jacque » Fri Dec 15, 2017 8:32 pm

cmhjon wrote:
Fri Dec 15, 2017 6:10 pm
Did I do something wrong?
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
Just some things to try.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

cmhjon
Posts: 43
Joined: Tue Aug 04, 2015 11:55 am

Re: Get File Type/Creator?

Post by cmhjon » Fri Dec 15, 2017 9:10 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4454
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Get File Type/Creator?

Post by jacque » Sat Dec 16, 2017 9:25 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

cmhjon
Posts: 43
Joined: Tue Aug 04, 2015 11:55 am

Re: Get File Type/Creator?

Post by cmhjon » Mon Dec 18, 2017 6:07 pm

I got it working now! :)

Thanks,
Jon

cmhjon
Posts: 43
Joined: Tue Aug 04, 2015 11:55 am

Re: Get File Type/Creator?

Post by cmhjon » Tue Jan 02, 2018 5:00 pm

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 :)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5962
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Get File Type/Creator?

Post by FourthWorld » Tue Jan 02, 2018 6:07 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

cmhjon
Posts: 43
Joined: Tue Aug 04, 2015 11:55 am

Re: Get File Type/Creator?

Post by cmhjon » Tue Jan 02, 2018 6:38 pm

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 :)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2511
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Get File Type/Creator?

Post by richmond62 » Tue Jan 02, 2018 6:44 pm

virtually all the content within is gibberish
Well, all that "gibberish" is text to tell Quark Express how to interpret the "meat" of the file.

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.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”