Saturday, October 21, 2017

#1 2017-07-13 04:57:33 pm

DPaquin
Member
Registered: 2012-01-23
Posts: 69

Open Finder window to a given location

I've created this short script which opens the finder to a desired directory location. The script is not elegant but work.

Applescript:

tell application "Finder"
   open "Data" -- display DATA directory/folder information
   tell the front window to set toolbar visible to false
   open (path to home folder as text) & "recVIDEO" --display /users/recVIDEO subfolder information
   tell the front window to set toolbar visible to false
end tell

In the meantime there is another directory I want to open but do not know how to get there.

For example, if I click on the listed Device (on the sidebar) there is a device with my name "Daniel Paquin" If I click on it, the dialog box showing the following folders appears:

- Network
- Macintosh HD
- NAS folder (share drive if mounted)
- SDHC card name (if mounted)


Would someone knows how to automatically point to that place ?

Lastly, at the top it shows the Name, Size, Date Created, Date modified. Let's say I only want to see the name nothing else for each file being displayed. Can that be done?

Thanks!

Daniel

Last edited by DPaquin (2017-07-13 11:51:39 pm)

Offline

 

#2 2017-07-14 02:50:52 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3199

Re: Open Finder window to a given location

DPaquin wrote:

I've created this short script which opens the finder to a desired directory location. The script is not elegant but work.

Applescript:

tell application "Finder"
   open "Data" -- display DATA directory/folder information
   tell the front window to set toolbar visible to false
   open (path to home folder as text) & "recVIDEO" --display /users/recVIDEO subfolder information
   tell the front window to set toolbar visible to false
end tell



You may use something like :

Applescript:

(*
[url]http://www.macscripter.net/post.php?tid=45838[/url]
*)


set thePaths to {}
set end of thePaths to "DATA" # On my machine, 1139 folders are named Data. I guess that a more precise path would be welcome.
set end of thePaths to (path to home folder as text) & "recVIDEO" --to display /users/recVIDEO subfolder information
set end of thePaths to "SSD 500" # an external HD
set end of thePaths to "Yosemite Install Disk - 10.10.4" # an USB card
repeat with aPath in thePaths
   my openThisFolder(aPath)
end repeat

on openThisFolder(hfsPath)
   tell application "Finder"
       try
           open folder hfsPath
           tell the front window to set toolbar visible to false
       end try
   end tell
end openThisFolder

In the meantime there is another directory I want to open but do not know how to get there.

For example, if I click on the listed Device (on the sidebar) there is a device with my name "Daniel Paquin" If I click on it, the dialog box showing the following folders appears:

- Network
- Macintosh HD
- NAS folder (share drive if mounted)
- SDHC card name (if mounted)


Would someone knows how to automatically point to that place ?



This "place" doesn't really exists.
It's just a way to display the connected devices in a single window.
Here in France it's named "iMac de ???????????" but I disable this feature in the Finder preferences.
I assume that it may be clicked with GUI Scripting but I'm too tired to try that this evening.

Lastly, at the top it shows the Name, Size, Date Created, Date modified. Let's say I only want to see the name nothing else for each file being displayed. Can that be done?



As far as I know we can't hide columns by script.
We may do it by hand.
Control click the title of a column reveal a popup menu in which we must uncheck the items which must be hidden.
I assume that it may be done with GUI Scripting but I'm too tired to try this evening.

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) vendredi 14 juillet 2017 21:50:28

Last edited by Yvan Koenig (2017-07-14 02:53:22 pm)

Offline

 

#3 2017-07-16 03:10:42 am

DPaquin
Member
Registered: 2012-01-23
Posts: 69

Re: Open Finder window to a given location

MANY thanks - Merci BEAUCOUP Yvan

I am trying to automate this process (opening file browsers) because I have users who will be working with me and never used MAC before. For sure it sound simple, however they have many other important task to do that I do not want them to get stuck on that. There are people who become very nervous just thinking they will have to work with MACs. They can get out of focus. This is why I am trying to minimise some of their stress.


This "place" doesn't really exists.
It's just a way to display the connected devices in a single window.
Here in France it's named "iMac de ???????????" but I disable this feature in the Finder preferences.

You are right on Yvan, it's the place where it's name .... This is unfortunate, for my purpose it's a nice window which provides some root directories other than the one found under Macintosh HD.


Lastly, at the top it shows the Name, Size, Date Created, Date modified. Let's say I only want to see the name nothing else for each file being displayed. Can that be done? As far as I know we can't hide columns by script.

This is unfortunate but will do without it.

Offline

 

#4 2017-07-16 04:19:01 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3199

Re: Open Finder window to a given location

I retrieved a piece of code poset on AppleScriptUserList by Shane STANLEY which will give you a neat way to get the list of devices available in the "iMac de ???????????" window.

Applescript:

# Three instructions required by the handler which use ASObjC
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set mountedDevices to my getMountedDevices()
tell application "Finder"
   repeat with aDevice in mountedDevices
       try
           open folder aDevice
       end try
   end repeat
end tell

on getMountedDevices()
   # this code was posted by Shane STANLEY on 2017/06/20 in the thread "Unmounted Disks" of applescript-users@lists.apple.com
   
   set theResult to do shell script "diskutil list -plist"
   -- make dictionary from property list
   set theResult to current application's NSString's stringWithString:theResult
   set pListDict to theResult's propertyList()
   -- extract relevant info
   set disksAndParitions to pListDict's objectForKey:"AllDisksAndPartitions"
   set partitionsArray to current application's NSMutableArray's array() -- to store values
   repeat with anEntry in disksAndParitions
       set thePartitions to (anEntry's objectForKey:"Partitions")
       if thePartitions = missing value then -- no partitions means a volume
           (partitionsArray's addObject:anEntry)
       else
           (partitionsArray's addObjectsFromArray:thePartitions)
       end if
   end repeat
   -- filter by Content type
   set thePred to current application's NSPredicate's predicateWithFormat:"Content == 'Apple_HFS'"
   set partitionsArray to partitionsArray's filteredArrayUsingPredicate:thePred
   -- get names
   return (partitionsArray's valueForKey:"VolumeName") as list
end getMountedDevices

Of course this code will no longer work when you will switch from Hfs to APFS.

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 16 juillet 2017 11:13:43

Offline

 

#5 2017-07-16 04:53:49 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5158

Re: Open Finder window to a given location

Yvan Koenig wrote:

This "place" doesn't really exist.



But it has its place in the Finder's dictionary:

Applescript:

tell application id "com.apple.finder" to open computer container


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Online

 

#6 2017-07-16 05:42:51 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3199

Re: Open Finder window to a given location

Thanks a lot Shane

I missed it.

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 16 juillet 2017 12:42:45

Offline

 

#7 2017-07-16 12:11:28 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3199

Re: Open Finder window to a given location

Here is a bit of GUIScripting disabling every columns minus Name one in list mode.

Applescript:

(*
[url]http://www.macscripter.net/post.php?tid=45838[/url]
*)


set the_App to application id ("com.apple.finder")
set path2app to path to the_App as text
set preferences_loc to localized string "AX24" from table "Localizable" in bundle (path2app as «class furl»)
set desktop_loc to localized string "AX70" from table "Localizable" in bundle (path2app as «class furl»)

tell application "Finder" to activate
tell application "System Events" to tell process "Finder"
   set frontmost to true
   repeat
       # Close every floating window
       if exists (window 1 whose subrole is "AXSystemFloatingWindow") then
           click (first button of (window 1 whose subrole is "AXSystemFloatingWindow") whose subrole is "AXCloseButton")
       else
           exit repeat
       end if
   end repeat
   repeat
       # Close every preferences window
       if exists (window 1 whose description is preferences_loc) then
           click (first button of (window 1 whose description is preferences_loc) whose subrole is "AXCloseButton")
       else
           exit repeat
       end if
   end repeat
end tell

tell application "Finder" to tell Finder window 1
   select it # In case there is no selected Finder window which would open options window for Desktop
   # Force Finder to use List View
   if current view is not list view then set current view to list view
end tell

tell application "System Events" to tell process "Finder"
   set frontmost to true
   -- properties of windows
   if not (exists (first window whose subrole is "AXSystemfloatingwindow")) then
       # The floating window isn't open, try to open it
       keystroke "j" using {command down}
   end if
   repeat 10 times
       delay 0.1
       try
           exists (first window whose subrole is "AXSystemfloatingwindow")
           exit repeat
       end try
   end repeat
   # The floating window is open
   
   tell (first window whose subrole is "AXSystemfloatingwindow")
       -- class of UI elements --> {checkbox, checkbox, static text, pop up button, pop up button, static text, group, button, button, static text}
       if its title = desktop_loc then error "Doesn't apply to Desktop !"
       tell group 1
           -- class of UI elements --> {static text, button, button, radio group, static text, pop up button, static text, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox}
           set checkBoxCount to count checkbox
           if checkBoxCount > 3 then
               # Disable the columns
               repeat with i from 1 to (checkBoxCount - 3)
                   if value of checkbox i = 1 then click checkbox i --"Date de modification"
               end repeat
           else
               error "requires Column mode !"
           end if
       end tell # group 1
   end tell
end tell

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 16 juillet 2017 19:10:20

Offline

 

#8 2017-07-17 11:38:15 am

DPaquin
Member
Registered: 2012-01-23
Posts: 69

Re: Open Finder window to a given location

THANKS EVERYBODY !

I would had never been able to do this coding myself. This is way over my head.

I REALLY want to say thanks for taking the time to help me out!

Daniel

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)