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: FourthWorld, heatherlaine, Klaus, kevinmiller

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

Get File Type/Creator?

Post by cmhjon » Thu Oct 26, 2017 4:08 pm

Hi everyone,

I have several versions of InDesign installed....

Is there a way to drop an InDesign file onto a LiveCode app that determines the files (version/creator?) and then opens the file with the appropriate InDesign version? I looked at the LC dictionary and found "fileType" but it seems that function is only used for setting the file type for files created by LC.

Thanks,
Jon

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Get File Type/Creator?

Post by jmburnod » Thu Oct 26, 2017 4:50 pm

Hi Jon,
I think you may get creator and file type using "detailed files" (OS X only).
Best regards
Jean-Marc
https://alternatic.ch

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

Re: Get File Type/Creator?

Post by Klaus » Thu Oct 26, 2017 5:05 pm

Yes, but only the abbreviation (creator) of the application that created the file and NOT the version of the app used for it.

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

Re: Get File Type/Creator?

Post by cmhjon » Thu Oct 26, 2017 9:54 pm

Is there a shell command that could be invoked within a script that could determine application version?

Thanks,
Jon

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

Re: Get File Type/Creator?

Post by FourthWorld » Thu Oct 26, 2017 11:07 pm

cmhjon wrote:
Thu Oct 26, 2017 9:54 pm
Is there a shell command that could be invoked within a script that could determine application version?
Of a document? Unlikely. That would require the app vendor to use a different creator code for each version, something I've seen only very few do. And since creator codes were largely deprecated with modern versions of OS X, I'd be surprised if vendors still bother to register them at all (does Apple even maintain that registry?).

If the document launches the correct version when double-clicked in the Finder, you can use LC's "launch document" command.

If not, you may investigate whether the document file species the version somewhere in its header, and store the paths to the various versions of the app you have installed, and use the "launch" command to launch the appropriate version for a given document.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Get File Type/Creator?

Post by MaxV » Fri Dec 01, 2017 1:18 pm

Files INDT are pure binary, so you can't read it.
Files INX are plain XLM, so you can try to extract some informations.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

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

Re: Get File Type/Creator?

Post by FourthWorld » Fri Dec 01, 2017 6:27 pm

MaxV wrote:
Fri Dec 01, 2017 1:18 pm
Files INDT are pure binary, so you can't read it.
Files INX are plain XLM, so you can try to extract some informations.
LC includes many features to read and convert elements in binary files. So with either form, I think you're onto something potentially quite useful for the OP there:

While most app publishers rarely use a different creator code for each version (if they use them at all anymore; Apple deprecated creator codes more than a decade ago), many apps rely on a "magic number" in the file's header to determine specifics about the file, such as perhaps the minimum app version it's compatible with.

If the OP can find info on whatever magic number scheme the app he wants to work with relies on, he may well be able to obtain the paths to the different app version on his hard drive and launch the one appropriate for a given document.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Get File Type/Creator?

Post by cmhjon » Fri Dec 01, 2017 8:40 pm

Hi FourthWorld,

Thank you for the reply. I'd really like to try to build an app that would do this but I don't know to read the gibberish within an InDesign file when opened with a text editor (let alone how to tell LC how to interpret it) :(

Best regards,
Jon

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Re: Get File Type/Creator?

Post by thatkeith » Tue Dec 05, 2017 9:40 pm

InDesign is probably the worst target app for this task – possibly for the same reason you want to do it!

InDesign documents will open whatever copy of InDesign is available, at which point (if the copy of InDesign is older than the one used to make the document, even by a tiny bit) the application will balk and complain mysteriously about "missing plugins." That's because, architecturally speaking, InDesign is basically a framework and a lot of plugins, and if any aren't available you're told so and the game stops. But that error message is stupendously unhelpful to almost all of humanity.

Anyway – I don't think an InDesign document contains any neat version code embedded in the header, just stuff that the app itself either understands or not. Sorry! :(

k
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

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

Re: Get File Type/Creator?

Post by FourthWorld » Tue Dec 05, 2017 10:01 pm

cmhjon wrote:
Fri Dec 01, 2017 8:40 pm
I'd really like to try to build an app that would do this but I don't know to read the gibberish within an InDesign file when opened with a text editor (let alone how to tell LC how to interpret it) :(
A quick search on Google for "InDesign file format specification" told me that it's a Zip file containing IDML, specified here:
http://wwwimages.adobe.com/content/dam/ ... cation.pdf

In LC we can open and read contents of Zip archives with the RevZip external. IDML is XML-based, which can be parsed with custom scripts or using LC's XML commands.

I think p44 of the PDF linked to above will get you where you need to go.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Get File Type/Creator?

Post by FourthWorld » Tue Dec 05, 2017 10:09 pm

Tip for lazy people (which definitely includes me, wherever possible): before going to the trouble of writing a set of routines to pull parts out of a Zip-based file, you can explore it easily enough by just add ".zip" to the file name. With that your file manager (Mac Finder, Windows Explorer, Gnome Nautilus) will just open it as any other Zip file. Then you can poke around easily, see what's there, and see if it's worth the trouble of proceeding to write something to automate getting parts out of it, such as with LC's Zip externals.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Get File Type/Creator?

Post by bogs » Tue Dec 05, 2017 11:24 pm

FourthWorld wrote:
Tue Dec 05, 2017 10:09 pm
Tip for lazy people (which definitely includes me, wherever possible)
<sic>... just add ".zip" to the file name. With that your file manager (Mac Finder, Windows Explorer, Gnome Nautilus) will just open it as any other Zip file. Then you can poke around easily, see what's there, and see if it's worth the trouble of proceeding to write something to automate getting parts out of it, such as with LC's Zip externals.
Seconded by an even lazier person:) Good tip.
Image

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

Re: Get File Type/Creator?

Post by cmhjon » Thu Dec 14, 2017 10:59 pm

I think I am getting closer to making this work however I've hit a snag that I don't understand. Using lessons from LC, this is the script I've pieced together:

on startup
local tFileName
put $1 into tFileName
loadFile tFileName
end startup

## We use an appleEvent to detect if the app was started by dragging a file onto it
on appleEvent pClass, pEventID, pSender
if pClass is "aevt" then
## This is an apple event
## We request the data about the apple event
request appleEvent data
put it into tFileName
if pEventID is "odoc" then
## This is an open document event
loadFile tFileName
end if
end if
pass appleEvent
end appleEvent

on loadFile pFileName
put URL ("file:" & pFileName) into field "Display"
if field "Display" contains "Adobe Indesign CS6" then
launch pFileName with "Adobe InDesign CS6.app"
else
answer "Not Found."
end if
--if field "Display" contains "Adobe InDesign CC 2017" then
--launch pFileName with "Adobe InDesign CC 2017.app"
--end if
--if field "Display" contains "Adobe InDesign CC 13.0" then
--launch pFileName with "Adobe InDesign CC 2018.app"
--end if
end loadFile


However, when I drag an InDesign CS6 file onto the compiled app (with the necessary CFBundleTypeExtension entry for an InDesign file), I get the "Not Found." dialog box but yet when the compiled app opens, I CAN find "Adobe InDesign CS6" in the "Display" field.

This will be a Mac-only application. What have I missed?

Thanks,
Jon

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

Re: Get File Type/Creator?

Post by Klaus » Thu Dec 14, 2017 11:35 pm

Hi Jon,

I'm not sure, but I think at "startup" the app is ABOUT to get loaded,
so maybe not all GUI elements, libraries etc. are available yet!?

Try this:

Code: Select all

on startup
   local tFileName
   put $1 into tFileName
   send "loadFile tFileName" to me in 30 
   ## half a second delay to give the engine tome to laod everything
   ## Maybe a shorter delay will also work, do some testing :-)
end startup
Best

Klaus

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

Re: Get File Type/Creator?

Post by cmhjon » Fri Dec 15, 2017 2:51 pm

Hi Klaus,

I think you hit the nail on the head. Unfortunately, it seems that no matter what I do, I can't get the information to show in the field before the app checks the field for the particular text string (even if I extend the loadFile time to 5 seconds). Loading the URL into a variable instead of the text field did not work. I also tried replacing startUp with openStack which also did not work.

Here's the script as I currently have it. Any other ideas?

Thank you so much!
Jon

on startup
local tFileName
put $1 into tFileName
send "loadFile tFileName" to me in 60
end startup

## We use an appleEvent to detect if the app was started by dragging a file onto it
on appleEvent pClass, pEventID, pSender
if pClass is "aevt" then
## This is an apple event
## We request the data about the apple event
request appleEvent data
put it into tFileName
if pEventID is "odoc" then
## This is an open document event
send "loadFile tFileName" to me in 60
end if
end if
pass appleEvent
end appleEvent

on loadFile pFileName
put URL ("file:" & pFileName) into field "Display"
if field "Display" contains "Adobe Indesign CS6" then
launch pFileName with "Adobe InDesign CS6.app"
else
answer "Not Found."
end if
--if field "display" contains "Adobe InDesign CC 2017" then
--launch pFileName with "Adobe InDesign CC 2017.app"
--end if
--if field "display" contains "Adobe InDesign CC 13.0" then
--launch pFileName with "Adobe InDesign CC 2018.app"
--end if
end loadFile

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”