0

The following works in Script Editor (or an Applescript App), but not in XCode:

tell application "Finder" to set folder_list to items of folder POSIX file "/Users"

Specifically, I get at runtime:

Finder got an error: Can’t make «class ocid» id «data optr000000002094230000600000» into type integer. (error -1700)  

If I try "double coercion":

...((folder POSIX file "/Users") as POSIX file)

I get:

Can’t make «class cfol» «script» of application "Finder" into type POSIX file. (error -1700) 

I did see something similar discussed here, but the solution did not work for me: "POSIX file" works in Applescript Editor, not in XCode

Thanks!

//Reid

p.s. I know I could just use "Macintosh HD:Users"... This works, unless somebody renamed their hard drive.

Community
  • 1
  • 1
Reid
  • 3
  • 1

2 Answers2

0

You can try to smoothen it out yourself, as I suspect the AppleScript editor does for you:

 tell application "Finder" to set folder_list to items of folder (POSIX file "/Users" as text)

What I did, was to coerce the posix file to text, otherwise it is of class furl which really isn't what Finder can take. I'd try to coerce your posix file statements to text, and see if that helps.

This compiles and runs, both from within my Editor, and from the script menu:

tell application "Xcode"
   tell application "Finder"
       set m to folder (POSIX file "/Users" as text)
       set n to name of m
       tell me to display alert n
   end tell
end tell

I hope this helps.

McUsr
  • 1,400
  • 13
  • 10
  • Thanks for the reply. I know it's gotta be something like that, but all it did was change the error: Can’t make «script» into type text. (error -1700) – Reid Mar 17 '15 at 14:25
  • I pasted your exact code block in just to double-check myself and got the same error. Whatever the final solution is, I hope it doesn't depend on "tell Xcode" anything, because I don't want the user to need it installed. – Reid Mar 17 '15 at 14:31
0

Applescript has the "path to" command to find paths to well known folders, like a user's home folder, desktop, documents folder etc. That's the best way to access the folders. You can see all the locations applescript knows in the Standard Additions applescript dictionary for the "path to" command. It also knows where the users folder is. As such I would write your code like this...

set usersPath to path to users folder
tell application "Finder" to set folder_list to items of usersPath
regulus6633
  • 18,848
  • 5
  • 41
  • 49