Thursday, January 19, 2017

#1 2008-02-12 11:59:39 am

Mark Munro
Registered: 2008-01-16
Posts: 175

Choose File: Problems with Packages


(choose file) as string

When using the "choose file" command (shown above), if the file you choose is a package (numbers, pages, and probably all or most of the "i-apps") the path returned will appear as a folder (ending with a colon ":") rather than a file.  This will cause an error if you later try to get a property of or manipulate the file. 

To get around this problem, you can add a couple of lines of code to detect and remove the colon from the file path before proceeding further as follows:


set pathToFile to (choose file) as string
if pathToFile ends with ":" then set pathToFile to text 1 thru -2 of pathToFile as string

This problem exists in 10.5 and may also exist in previous versions of OS X.



#2 2008-03-31 10:40:45 pm

Bruce Phillips
Registered: 2004-07-15
Posts: 2649

Re: Choose File: Problems with Packages

Mark Munro wrote:

This will cause an error if you later try to get a property of or manipulate the file.

Would you give an example?



#3 2008-04-02 08:05:20 am

Nigel Garvey
From: Warwickshire, England
Registered: 2002-11-19
Posts: 4159

Re: Choose File: Problems with Packages

Hi, Mark.

The trailing colon isn't a bug, nor is it new in Leopard. Packages are containers, and coercions to text from container aliases have always ended with colons. choose file allows packages to be chosen because it's a user-interaction command, and users are supposed to think of packages as files. It returns an alias and that's the end of its involvement. The as string coercion that follows works from the alias, not knowing it came from choose file. It's up to scripters to make the necessary allowances, but it's not a bug.




Board footer

Powered by FluxBB

[ Generated in 0.042 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)