Sunday, May 9, 2021

#1 2021-04-21 10:31:47 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 703

Any one else share the same experience

My approach is to stay away from tell block of Finder as much I could. To be honest I couldn't
remember when I need to ask Finder anything I couldn't get else where.

Any one else share the same experience??

Applescript:

tell application "Finder" to tell home
   set a to (folders as alias list)
end tell

set PosixList to {}
repeat with i from 1 to (count a)
   set theItem to (item i of a) as text
   set theItem to theItem's POSIX path
   set the end of PosixList to theItem
end repeat

tell application "Finder" to tell home
   set thePOSIX to (its folder "Desktop" as text)'s POSIX path
   set theHFS to (its folder "Desktop") as text
   set theAlias to (its folder "Desktop") as alias
   set theFile to (its folder "Desktop") as «class furl»
   set theURL to its URL of (its folder "Desktop")
end tell

return {POSIX path:thePOSIX, |POSIX list|:PosixList, HFS:theHFS, |Alias|:theAlias, |Alias list|:a, |File|:theFile, URL:theURL}


if you are the expert, who will you call if its not your imagination.

Offline

 

#2 2021-04-21 10:53:55 am

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

Re: Any one else share the same experience

I dropped several call to Finder.

Applescript:

tell application "Finder" to tell home
   set a to (folders as alias list)
end tell

set PosixList to {}
repeat with i from 1 to (count a)
   set theItem to (item i of a) --no need to coerce as text
   set theItem to theItem's POSIX path
   set the end of PosixList to theItem
end repeat
set theAlias to path to desktop folder -- return an alias
set thePOSIX to theAlias's POSIX path
set theHFS to theAlias as text
set theFile to theAlias as «class furl»
tell application "Finder" to set theURL to URL of theAlias


return {POSIX path:thePOSIX, |POSIX list|:PosixList, HFS:theHFS, |Alias|:theAlias, |Alias list|:a, |File|:theFile, URL:theURL}

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 21 avril 2021 18:51:10

Offline

 

#3 2021-04-21 11:43:58 am

wch1zpink
Member
Registered: 2011-08-20
Posts: 16

Re: Any one else share the same experience

You can also shrink this

Applescript:

set PosixList to {}
repeat with i from 1 to (count a)
set theItem to (item i of a) as text
set theItem to theItem's POSIX path
set the end of PosixList to theItem
end repeat

down to this

Applescript:

set PosixList to {}
repeat with i from 1 to (count a)
   set the end of PosixList to POSIX path of (item i of a)
end repeat

Offline

 

#4 2021-04-21 11:56:09 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 703

Re: Any one else share the same experience

@Yvan
Thanks, I agree with you with everything you wrote.

The test case was to show something possible in a tell block of Finder.
As I state before I couldn't remember when I use tell block of Finder to do anything useful.

Let me rephrase the question, when would it make sense to use tell block of Finder
to ask something we couldn't get else where?

Ps.
To get URL we could use System Events
tell application "System Events" to set theURL to URL of theAlias

Last edited by Fredrik71 (2021-04-21 12:01:33 pm)


if you are the expert, who will you call if its not your imagination.

Offline

 

#5 2021-04-21 10:05:57 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1788

Re: Any one else share the same experience

Fredrik71 wrote:

To get URL we could use System Events


Yes, in your example from post# 1, it's best not to use the Finder at all. For example, the following script does the same thing as your Finder script, but 10 times faster.

Applescript:


tell application "System Events"
   tell home folder
       set a to folders
       set PosixList to POSIX path of folders
   end tell
   tell desktop folder
       set thePOSIX to POSIX path
       set theHFS to path
       set theAlias to path as alias
       set theFile to path as «class furl»
       set theURL to URL
   end tell
end tell

return {POSIX path:thePOSIX, |POSIX list|:PosixList, HFS:theHFS, |Alias|:theAlias, |Alias list|:a, |File|:theFile, |URL|:theURL}

As for your question, the Finder is more convenient to use with handling objects and properties of objects that belong only to it. For example, with folder windows, with comments, Finder settings panels, Finder-selections, etc. Therefore, the Finder is best avoided, but I would not go into the ecstasy of boycotting it.

Here's beautiful example of how you can't do without the Finder. Not so long ago, a question was asked here about how to implement a choose dialog from the location of the computer-container object of the Finder application, and what it is and how to access it. I can say now, that you can access this location correctly only using Finder:

Applescript:


tell application "Finder"
   open computer container
   set selection to {}
   activate
   display dialog "Choose item from computer location" buttons {"OK", "Cancel"}
end tell

repeat
   tell application "Finder" to if not (selection is {}) then return selection
   delay 0.02
end repeat

Last edited by KniazidisR (2021-04-21 11:15:34 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#6 2021-04-22 02:48:10 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 703

Re: Any one else share the same experience

@KniazidisR

To open computer-container object

Could be done with open location

Applescript:

open location "file://localhost/Volumes/"

If 99% of the times the user do selection of items in Volumes, then this would make more sense.

Applescript:

set theAliasList to (choose file default location "/Volumes" with multiple selections allowed)
set thePosixList to {}
repeat with i from 1 to count theAliasList
   set the end of thePosixList to (item i of theAliasList)'s POSIX path
end repeat
return thePosixList


if you are the expert, who will you call if its not your imagination.

Offline

 

#7 2021-04-23 11:15:27 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1788

Re: Any one else share the same experience

Don't you notice that you are opening a different location in the window? Anyway. Here's another example with computer_object. Try this without Finder:

Applescript:


tell application "Finder"
   try
       close Finder windows
   end try
   open computer container
end tell

Also, your love of repeat loops is not clear:

Applescript:


tell application "System Events" to set thePosixList to POSIX path of every file of folder "/Volumes"

set thePosixList to choose from list thePosixList

Last edited by KniazidisR (2021-04-23 11:49:02 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#8 2021-04-24 03:10:34 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 703

Re: Any one else share the same experience

@KniazidisR, thank you for your input.

People long before me ask the same question. The terminology of Finder have many
strange/errors and it have been pointed out here in this forum as well many times.

ex.
Terminology say that computer container has a class of disk but its not a disk itself.
So that why this will not work, but the terminology say it does.

Applescript:

tell application "Finder" to tell computer container
   set theName to its name
   tell disk theName to its properties
end tell

Go Computer Show:
Macintosh HD, Network and Portable SSD
Ps. If no Network is attached to the computer its empty, meaning you couldn't do anything with it.

Go /Volumes Show:
Macintosh HD, Portable SSD same as Go Computer. It could also show Recovery partition that you
will not see in GO Computer

If you then mount a Server ex. ftp://ftp.sunet.se
You will see its mount as Volume. So anything you could do in Go Computer you could also
do in /Volumes. 

I'm not sure why you think Go Computer or open computer container is so special in Finder.
Try this...

Applescript:

do shell script "open /System/Library/CoreServices/Finder.app/Contents/Applications/Computer.app"

Last edited by Fredrik71 (2021-04-24 03:20:19 am)


if you are the expert, who will you call if its not your imagination.

Offline

 

#9 2021-04-24 04:04:00 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1788

Re: Any one else share the same experience

Yes you are right. This special Finder functionality is useless without a server in a window, and a connected server can be dispensed with without a Finder (via "/Volumes"). Apparently, I chose a bad example. sad

Last edited by KniazidisR (2021-04-24 04:08:00 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#10 2021-04-24 04:42:57 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 703

Re: Any one else share the same experience

Here is other way to open computer container

From the Computer.app info.plist you find the CFBundleIdentifier

Applescript:

try
   tell application id "com.apple.finder.Open-Computer" to activate
end try

Last edited by Fredrik71 (2021-04-24 04:45:56 am)


if you are the expert, who will you call if its not your imagination.

Offline

 

#11 2021-04-24 06:12:27 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 703

Re: Any one else share the same experience

@KniazidisR
You got me thinking, I like that..

Instead of repeat loop we could do it like this if the desire is to return POSIX path

Applescript:

use framework "Foundation"
use scripting additions

set theAliasList to (choose file default location "/Volumes" with multiple selections allowed)
set theURL to current application's NSArray's arrayWithArray:theAliasList
return (theURL's |path|) as list

Last edited by Fredrik71 (2021-04-24 06:13:10 am)


if you are the expert, who will you call if its not your imagination.

Offline

 

#12 2021-04-29 01:17:46 am

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 152

Re: Any one else share the same experience

I use Finder if I need to use its specific commands reveal, select, empty, and eject, or one of its properties insertion location, and selection.

However, I limit its involvement to performing that task only, passing it lists of file references from System Events in a format that it can understand, or having it return an alias list.

I'll also often call move, duplicate, and delete through Finder, as System Events's delete is permanent, and the other operations when performed by Finder can be easily undone with ⌘-Z.  It's worth remembering that all of these commands accept lists of plain text HFS paths.  System Events's path property is one I use a lot.

The only other situation Finder is useful is in carefully constructed whose filters and very specific calls to entire contents, which should otherwise be avoided.  One of these use cases is in enumerating scriptable applications.


A vanilla way to avoid the loop:

Applescript:

set theAliasList to (choose file default location "/Volumes" with multiple selections allowed)
set text item delimiters to linefeed & ":Volumes:"
paragraphs of (POSIX path of ("" & theAliasList))

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)