Popup button selection

Hi
The script below basically inserts file names into a popup button when the button “SK_KNIVES” is clicked , I then select from the popup button, click “get” then “Illustrator opens the selected file”.
The problem is a error, which says “Can’t make «class titl» of «class cuMI» of «class popB» “_itemlist” into type reference. (-1700)”, ive tried using “alias” etc after “popup button “_itemlist” or” open _selecteditem" but have had no success, can someone please point out what I am missing, to have Illustrator activate the selected file in the popup button.

on clicked theObject
	if name of theObject is "SK_KNIVES" then
		set _path to "Macintosh HD:Users:Desktop:"
		tell application "Finder"
			set _list to name of every file of folder _path
		end tell
		tell window "main"
			delete every menu item of menu of popup button "_itemlist"
			repeat with each_Item in _list
				make new menu item at the end of menu items of menu of popup button "_itemlist" with properties {name:each_Item, title:each_Item, enabled:true}
			end repeat
		end tell
	end if
	-----
	if name of theObject is "get" then
		set _selecteditem to title of current menu item of popup button "_itemlist"
		tell application "Adobe Illustrator"
			activate
			open _selecteditem
		end tell
	end if
	-----
	if name of theObject is "cancel" then
		quit me
	end if
end clicked

Cheers
Budgie

Hi Budgie,

1.) your path to desktop misses the user,
in a Finder tell block there is a shortcut,
because the “root” folder of the Finder is the desktop of the current user

tell application "Finder" to set _list to name of every file

2.) The error occurs, because the reference is not complete

set _selecteditem to title of current menu item of popup button "_itemlist" of window "main"

Hi StefanK

Thanks for that, it’s normally the obvious that is over looked. :smiley:

Cheers
Budgie

Hi

I have changed my script as suggested which gives me the result im after bar the opening of the file in Illustrator, do I need to use something like a POSIX path to get illustrator to recognise what the “_selecteditem” of the pop up button is?, im not sure?

the error I am getting is: “File Q22604-PROOF.pdf wasn’t found. (-43)”

if name of theObject is “get” then
set _selecteditem to title of current menu item of popup button “_itemlist” of window “main”
tell application “Adobe Illustrator”
activate
open _selecteditem as alias

	end tell
end if

Cheers
Budgie

You have only the name, but you need the whole path of the file
for example


...
set _selecteditem to title of current menu item of popup button "_itemlist" of window "main"
tell application "Finder" to set FileToOpen to ((get 1st file of _path whose name is _selecteditem) as alias)
tell application "Adobe Illustrator" to open FileToOpen
...

Hi StefanK

I implemented your suggestion which yielded this error:

Can’t get file 1 of “KNIFE DRAWINGS:”. (-1728) --(“KNIFE DRAWINGS:” is a mounted volume)

so I added “as alias” to the end of this string:

set _selecteditem to title of current menu item of popup button “_itemlist” of window “main” as alias

and had this error returned:

File TK101174 - C4 TS 00 House .dwg wasn’t found. (-43)

not quite sure what to do here?

Budgie

Hi Budgie,

two explanations to my suggestion above:
the variable _selecteditem is just a string, not a (string) path
the variable _path must be a file specifier or an alias

so for example

set _selecteditem to "TK101174 - C4 TS 00 House .dwg"
set _path to "KNIFE DRAWINGS" as alias -- class alias
tell application "Finder" to set FileToOpen to ((get 1st file of _path whose name is _selecteditem) as alias) -- _path = alias
tell application "Adobe Illustrator" to open FileToOpen

or

set _selecteditem to "TK101174 - C4 TS 00 House .dwg"
set _path to "KNIFE DRAWINGS" -- class string
tell application "Finder" to set FileToOpen to ((get 1st file of folder _path whose name is _selecteditem) as alias) -- folder _path = file specifier
tell application "Adobe Illustrator" to open FileToOpen

Hi

Ive been mucking around with this on and of for a few days now, using the two different suggestions above from StefanK, they throw the same error.

Finder got an error: Can’t get file 1 of alias “KNIFE DRAWINGS:” whose name of it = “8120SO.pdf”. (-1728)

So decided it wasn’t the code, it was what I was getting the code to do, or in this case not do. “KIFE DRAWINGS” is the top level folder of a mounted volume, the files are being sourced from files within folders, within folders of this volume, so a repeat is required to go through all the folders to obtain the selected file from the selected item of the pop up button.
How would I implement the repeat using this?

if name of theObject is "get" then
	set _path to "KNIFE DRAWINGS:" as alias
	set _selecteditem to title of current menu item of popup button "_itemlist" of window "main" as text
	tell application "Finder" to set FileToOpen to ((get 1st file of _path whose name is _selecteditem) as alias)
	tell application "Adobe Illustrator" to open FileToOpen
end if

Budgie

ok, got is sorted, no repeat loop required, this works fine for me

if name of theObject is "get" then
	set _path to "KNIFE DRAWINGS:"
	set _selecteditem to title of current menu item of popup button "_itemlist" of window "main" as text
	tell application "Finder" to set FileToOpen to ((get 1st file of entire contents of folder _path whose name is _selecteditem) as alias)
	tell application "Adobe Illustrator" to open FileToOpen
end if

thanks for your help StefanK

cheers
Budgie