Sunday, July 22, 2018

#1 2003-04-12 10:10:43 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Help using browser to select and display disks

I am having trouble with this script. It is a stupid script, I admit, but I wanted something that would pop up a list of available disks and allow me to select which ones to eject. It also has a button to eject all the disks. However, I can't get the "Browser" to work. I tried creating a one column browser, based on Apple's example, that would display a list of all mounted volumes. However, it doesn't do anything.

The interface is simple enough: A window (MainWindow) with two buttons (EjectAll and Select), as well as a drawer (Drawer) and a browser in the drawer (Browser). Everything works so far, except I can use the Browser at all.

Anyone have any suggestions?


-- EjectTheDisks.applescript
-- EjectTheDisks

property diskNames : {}

on launched theObject
end launched

on clicked theObject
   if name of theObject is "EjectAll" then
       tell application "Finder"
           eject the disks
       end tell
   end if
   if name of theObject is "Select" then
       tell window "MainWindow"
           set currentState to state of drawer "Drawer"
           if currentState is equal to drawer closed or currentState is equal to drawer closing then
               tell application "Finder"
                   set diskNames to name of every disk as list
               end tell
               set path separator of browser "Browser" of drawer "Drawer" to ":"
               tell browser "Browser" of drawer "Drawer" to update
               tell drawer "Drawer" to open drawer
               tell drawer "Drawer" to close drawer
           end if
       end tell
   end if
end clicked

on will close theObject
end will close

on awake from nib theObject
   tell application "Finder"
       set diskNames to name of every disk as list
   end tell
   tell window "MainWindow"
       tell drawer "Drawer" to open drawer
   end tell
   tell browser "Browser" of drawer "Drawer" of window "MainWindow" to update
end awake from nib

on will display browser cell theObject row theRow browser cell browserCell in column inColumn
   tell application "Finder"
       set cellContents to displayed name of disk (item theRow of diskNames as string)
       set isLeaf to false
   end tell
   set string value of theCell to cellContents
   set leaf of theCell to isLeaf
end will display browser cell

on number of browser rows theObject in column inColumn
   set rowCount to count of diskNames
   return rowCount
end number of browser rows


One mans trash is another mans treasure

Filed under: Finder



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)