I can’t figure out how to set the starting directory of open panel to the users home directory.
on choose menu item theObject
if the name of theObject = "openFile" then
set can choose directories of open panel to true
set can choose files of open panel to true
display open panel
end if
end choose menu item
I’ve tried “set path of open panel to (system attribute “HOME”)” and display open panel with path (system attribute “HOME”) but both produce errors.
Thanks! I’m reading up more on what the display command can effect.
I’m stuck at the second part now though, I’m chosing the file but as far as I can tell the “on panel ended” function is never being called.
on launched theObject
end launched
on choose menu item theObject
if the name of theObject = "openFile" then
set can choose directories of open panel to true
set can choose files of open panel to true
display open panel in directory (system attribute "HOME")
end if
end choose menu item
on panel ended theObject with result withResult
if withResult is 1 then
set inputFile to item 1 of (path names of open panel as list)
set title of window "main" to inputFile
end if
end panel ended
Now, when I had the panel attached to my “main” window, this function worked fine. I had to check the “Panel->Panel Ended” handler in the Applescript NSWindow Inspector for window “main”.
When I look at the Inspector for Mainmenu.nib for “File->Open” there is a “Choose menu item” which I’ve checked and a update menu item which I have not.
So how do I access the chosen file path via File->Open?
I believe ˜on panel ended’ is only called when the object being displayed is attached to a window. Otherwise, the result should come immediately after the ˜display’ command.
on choose menu item theObject
if the name of theObject = "openFile" then
set can choose directories of open panel to true
set can choose files of open panel to true
display open panel in directory (system attribute "HOME")
set test to item 1 of (path names of open panel as list)
end if
display dialog test
end choose menu item