code runs in script editor not in xcode app

the piece of code below works exactly as I require from script editor, I have now added it to my xcode project as a run only scpt file and running it from there,

set t to "12345-A"
set Files_Found to paragraphs of (do shell script "mdfind -onlyin '/Volumes/Macintosh HD/'" & space & quoted form of t)
set File_List to {}
repeat with i in Files_Found
	set {name:FileName, name extension:FileExtension} to info for POSIX file i as alias
end repeat

it runs fine right upto this line

set {name:FileName, name extension:FileExtension} to info for POSIX file i as alias

which now throws an error

could some one tell me why please?

You can’t use POSIX file as a specifier. See the chapter ‘AppleScript Gotchas II’ in my book, or:

:rolleyes::lol: damm, I keep forgetting this, 'ive done this three times now over a period of time, ill have to pin this page to my forehead


What you’re doing here is trying to set the name and the extension when what you want to do is get them.

The script below works fine both in script editor and in the init handler of an XCode 3.6 project, displaying the list dialog when the app launches, notwithstanding what Shane says about POSIX file.

I haven’t tried it in XCode 4.5.1 for reasons mentioned in another thread.


set _search_string to "12345-A"
set _cmd_output to do shell script "mdfind -onlyin /" & space & quoted form of _search_string

try -- this will give an error if there are no hits
	set _search_results to paragraphs of _cmd_output
on error _e
	display dialog _e
	return 0
end try

set _filename_list to {}
repeat with _pathname in _search_results
	set _file to _pathname as POSIX file
	--set  end of _file_list to the {name:FileName, name extension:FileExtension} to info for _file
	set _file_info to info for the _file
	set {_name, _suffix} to {name, name extension} of _file_info
	set end of _filename_list to _name & ", " & _suffix
end repeat
choose from list _filename_list with empty selection allowed

No, the syntax

set {name:FileName, name extension:FileExtension} to info for aliasSpecifier

does exactly the same as

 set {FileName, FileExtension} to {name, name extension} of info for aliasSpecifier

You’re using it in a coercion, which is fine; it’s as a specifier that it won’t work.