How do I know a file is a package?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How do I know a file is a package?
If a file is a package in OS X then it appears as a directory to "the folders" and its contents as various files and folders. However, you can not copy this structure piece-by-piece as you could an ordinary folder but must use revCopyFile on the bundle itself. This copies all contents successfully.
The problem is, how do I know a directory encountered by "the folders" is actually a bundle, so that I know which approach to use?
The problem is, how do I know a directory encountered by "the folders" is actually a bundle, so that I know which approach to use?
Re: How do I know a file is a package?
Davidv ,
If the last four characters of a folder path is ".app" then it is an application package. Surely, you can copy the files of such a package one by one, but you have to make sure that you preserve permissions. You may also need to execute the touch command from the terminal (or shell function) afterwards.
Best,
Mark
If the last four characters of a folder path is ".app" then it is an application package. Surely, you can copy the files of such a package one by one, but you have to make sure that you preserve permissions. You may also need to execute the touch command from the terminal (or shell function) afterwards.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: How do I know a file is a package?
There are many common package types with different suffixes, including app, bundle, pkg, vst, component, plugin, cfm, ape, colorPicker and others which are found in many different locations. Some extensible applications muddy the waters further by inventing names for their bundles, such as sugar or tmplugin. There is nothing magical about using a "." within a directory name so simply assuming any folder that contains a period within a string is a package of some sort would be not a good idea. Finding such a directory, it may be considered a reasonably reliable test to check to see if the first level inside it is another directory called "Contents", although this couldn't be thought of as foolproof.
It may be a little more reliable, if you feel so inclined, to do some research and compile a list of extensions known to be used to identify packages and test suspicious folders against it, however the only foolproof way is to query, somehow or another, the data stored in Launch Services.
Below is a link which should give you enough info to get started. I haven't done any further looking, so can't say there isn't a more convenient and direct way of getting the info - say, returning the flags or constants for a particular directory using its path - than running a dump and filtering (somehow) the result, but it seems a possiblity. Anyhow, this ought to give you an idea of where to look and what questions to ask, if you're interested:
http://stackoverflow.com/questions/1211 ... x-terminal
http://developer.apple.com/mac/library/ ... g-BCIHFFIA (search the page for "package")
It may be a little more reliable, if you feel so inclined, to do some research and compile a list of extensions known to be used to identify packages and test suspicious folders against it, however the only foolproof way is to query, somehow or another, the data stored in Launch Services.
Below is a link which should give you enough info to get started. I haven't done any further looking, so can't say there isn't a more convenient and direct way of getting the info - say, returning the flags or constants for a particular directory using its path - than running a dump and filtering (somehow) the result, but it seems a possiblity. Anyhow, this ought to give you an idea of where to look and what questions to ask, if you're interested:
http://stackoverflow.com/questions/1211 ... x-terminal
http://developer.apple.com/mac/library/ ... g-BCIHFFIA (search the page for "package")
Last edited by wsamples on Wed May 19, 2010 5:47 am, edited 1 time in total.
Re: How do I know a file is a package?
Ok, looking at this some more, including actually reading some more at the first link provided above, there is something that you may find really useful if you can get it to work conveniently. (This caveat because the launch command doesn't seem all that happy about working with shell() in a rev script )
Running the command launch -f [some/path/to/file] in terminal returns a summary of information from Launch Services. If your target is a package, the last word on the first line of the returned info will be "package". Give it a try! If you can figure out how to get it to cooperate with rev, this offers the best combination of simplicity and accuracy. For some reason trying to evoke it with the rev shell() funtion returns that the command cannot be found, despite the fact that the same shell runs it just fine in the terminal. Interestingly, 'whereis launch' fails to return a result. If you download a binary for 'launch' from http://web.sabi.net/nriley/software/ and point the shell function to this binary, all should work, but be reminded you'll have to take care to escape spaces in the pathname
Hope this helps!
Running the command launch -f [some/path/to/file] in terminal returns a summary of information from Launch Services. If your target is a package, the last word on the first line of the returned info will be "package". Give it a try! If you can figure out how to get it to cooperate with rev, this offers the best combination of simplicity and accuracy. For some reason trying to evoke it with the rev shell() funtion returns that the command cannot be found, despite the fact that the same shell runs it just fine in the terminal. Interestingly, 'whereis launch' fails to return a result. If you download a binary for 'launch' from http://web.sabi.net/nriley/software/ and point the shell function to this binary, all should work, but be reminded you'll have to take care to escape spaces in the pathname
Hope this helps!
Re: How do I know a file is a package?
More info... It may be that launch is not something that Apple actually provides. I see that I had had it installed through fink. I'm not sure why this should have caused the erratic refusal to run via rev's shell() function, but I now have it installed in /usr/local/bin and it does work properly with rev. For this to work as part of software distributed to other users, a binary would have to be supplied and your script pointed to it, although that shouldn't be too difficult
-
- VIP Livecode Opensource Backer
- Posts: 3991
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: How do I know a file is a package?
applescript could tell you also if a file is a package. (I always shy away from the terminal )
regards
Bernd
Code: Select all
set x to choose file
tell application "System Events"
set y to the properties of x
set z to package folder of x
end tell
return z
Bernd
-
- Posts: 845
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Re: How do I know a file is a package?
Would Bernd (or someone else explain) how the Applescript works from within a livecode script. Having just run into this feature I think that "the files" just returns a list of files e.g. OmniOutliner3 files which are packages are not listed, whereas "the folders" returns both finder folders and application package directories. So I am looking for a method of removing finder folders from the list of folders that is returned by the folders command.
best wishes
Skids
Skids
-
- VIP Livecode Opensource Backer
- Posts: 3991
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: How do I know a file is a package?
Hi Simon,
nice to see/hear/read from you.
instead of explaining I made a little stack that uses apple script to find out if a "folder" is actually a package. As you found Livecode lists the bundles/packages as folders.
Point the stack to a folder that contains a mix of finder folders and packages. It will list all folders on the left and packages on the right.
Look at the script of the button.
I hope I got it right what you want.
Feel free to ask if anything is not working as you like.
(mind you there might be problems with high ascii characters in file names, did not test)
Kind regards
Bernd
nice to see/hear/read from you.
instead of explaining I made a little stack that uses apple script to find out if a "folder" is actually a package. As you found Livecode lists the bundles/packages as folders.
Point the stack to a folder that contains a mix of finder folders and packages. It will list all folders on the left and packages on the right.
Look at the script of the button.
I hope I got it right what you want.
Feel free to ask if anything is not working as you like.
(mind you there might be problems with high ascii characters in file names, did not test)
Kind regards
Bernd
- Attachments
-
- findAppPackages.livecode.zip
- (2.43 KiB) Downloaded 278 times
-
- VIP Livecode Opensource Backer
- Posts: 3991
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: How do I know a file is a package?
Hi Simon,
here is a version that puts much of the work into applescript which makes it a bit faster instead the roundtrips livecode appleScript livecode for each file. For large folders with many subfolders and packages it can still be a little slow.
It does work with german umlaute in file names.
Kind regards
Bernd
here is a version that puts much of the work into applescript which makes it a bit faster instead the roundtrips livecode appleScript livecode for each file. For large folders with many subfolders and packages it can still be a little slow.
It does work with german umlaute in file names.
Kind regards
Bernd
- Attachments
-
- findAppPackages_0.2.livecode.zip
- (2.71 KiB) Downloaded 279 times
-
- Posts: 845
- Joined: Wed Nov 04, 2009 11:41 am
- Location: Gunthorpe, North Lincs, UK
Re: How do I know a file is a package?
Hi Bernd,
Thanks for the example stack. Its good to be back using Livecode; I've not touched it for many months but I hope to create a few utilities this winter.
I had not realised that it was quite so simple to mix Applescript and Livecode.
Simon
Thanks for the example stack. Its good to be back using Livecode; I've not touched it for many months but I hope to create a few utilities this winter.
I had not realised that it was quite so simple to mix Applescript and Livecode.
Simon
best wishes
Skids
Skids