Wednesday, January 19, 2022

#1 2012-11-10 09:10:55 am

adayzdone
Member
From:: New York
Registered: 2011-01-25
Posts: 525

Duplicate: Finder vs System Events

I am interested in learning more about the duplicate command's behavior. Does one of the solutions below offer advantages over the others? I am also curious about other implications or nuances of a Finder file vs a System Events file.

Applescript:

set filePath to ((path to desktop as text) & "Test File.txt")
set folderPath to ((path to desktop as text) & "Test Folder")

tell application "Finder"
   set finderFile to file filePath
   set finderFolder to folder folderPath
end tell

tell application "System Events"
   set seFile to file filePath
   set seFolder to folder folderPath
end tell

--duplicate finderFile to finderFolder
--duplicate seFile to seFolder -- error

-- Finder
--tell application "Finder" to duplicate filePath to folderPath
--tell application "Finder" to duplicate finderFile to finderFolder
--tell application "Finder" to duplicate seFile to seFolder -- error

-- System Events
--tell application "System Events" to duplicate finderFile to finderFolder
--tell application "System Events" to duplicate filePath to folderPath -- error
--tell application "System Events" to duplicate seFile to seFolder -- error

9YE4R.png

Finder:
kgfjm.png

System Events:
lfCBN.png

Last edited by adayzdone (2012-11-10 10:39:02 am)

Offline

 

#2 2012-11-10 09:32:17 am

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Duplicate: Finder vs System Events

Hello! And how interesting! smile

I am interested in learning more about the duplicate command's behavior. Does one of the solutions below offer advantages over the others? I am also curious about other implications or nuances of a Finder file vs a System Events file.


I have some reflections as to the second part of your question, given that the terms for using the duplicate command is the same. (Given the routing surpressed option for Finder's version, I gather the Finder version to be better to use over Networks,, guessing totally unualified over this.)

The advantage of using system events commands where I can are at least two fold as I see it, I am posix/hfs independent, is the first, (less typing smile ). The other is that System Events doesn't carry a lot of windows around that may need updates, so scripting System Events, doesn't lead to a whole other set of "side effects".

(Which may or may not slow down your scripts responsiveness, if it is more to it than just duplicating a file.)

But from the Dictionaries, it also seems that Finder is a tad more user friendly if you need aa reference to the new disk item. Hmmm I wonder how System Events duplicate files, with regards to item names.

Last edited by McUsr (2012-11-10 09:35:03 am)


Mercurial vcs is a joy to use for scripting.


Filed under: duplicate

Offline

 

#3 2012-11-11 09:22:47 am

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1055

Re: Duplicate: Finder vs System Events

Hi. Another difference is that files living on the desktop don't need to be specified by path, when working with Finder.

Applescript:

tell application "Finder" to open (duplicate file ""Test File.txt" to folder "testFolder")

Offline

 

#4 2012-11-11 10:01:19 am

adayzdone
Member
From:: New York
Registered: 2011-01-25
Posts: 525

Re: Duplicate: Finder vs System Events

files living on the desktop don't need to be specified by path, when working with Finder.


I did not know that, thanks.

Another observation ... If I run this System Events command two times (so the file already exists in the destination folder), I get a Finder error:

Applescript:

tell application "System Events" to duplicate finderFile to finderFolder

error "Finder got an error: An item with the same name already exists in this location." number -15267

Offline

 

#5 2012-11-11 11:15:52 am

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

Re: Duplicate: Finder vs System Events

On my side, I dropped the Finder for every tasks which are not related to the windows.

To do its duty, the Finder is supposed to trigger System Events so I feel logical to do that by myself.
Sometimes I drop System Events and use do shell script but it's not always sparing time.
As ASObjC Runner is always loaded on my mac, I use its file dedicated functions when scripts are just for my needs.

Yvan KOENIG (VALLAURIS, France) dimanche 11 novembre 2012 18:15:31

Offline

 

#6 2012-11-11 11:36:29 am

adayzdone
Member
From:: New York
Registered: 2011-01-25
Posts: 525

Re: Duplicate: Finder vs System Events

To do its duty, the Finder is supposed to trigger System Events so I feel logical to do that by myself.


But in this case you must reference the folder and file in the Finder before the System Events command will work, so it is almost reversed. I am curious if there is any advantage in doing this or if leaving the duplicate command to Finder is the way to go.

Offline

 

#7 2012-11-11 12:32:51 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5473

Re: Duplicate: Finder vs System Events

adayzdone wrote:

Another observation ... If I run this System Events command two times (so the file already exists in the destination folder), I get a Finder error:

Applescript:

tell application "System Events" to duplicate finderFile to finderFolder

error "Finder got an error: An item with the same name already exists in this location." number -15267


That's to be expected if finderFile and finderFolder are Finder references. System Events has no idea what to do with them, so they're passed to their owner.

Last edited by Nigel Garvey (2012-11-11 12:33:21 pm)


NG

Offline

 

#8 2012-11-11 01:47:12 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Duplicate: Finder vs System Events

adyazdone wrote:

But in this case you must reference the folder and file in the Finder before the System Events command will work, so it is almost reversed. I am curious if there is any advantage in doing this or if leaving the duplicate command to Finder is the way to go.


If I get references or such through the UI of Finder, then I use Finder. If not, System Events.

(As long as there aren't any special considerations, that makes me have to involve shell scripting anyway.)

Last edited by McUsr (2012-11-11 01:47:34 pm)


Mercurial vcs is a joy to use for scripting.


Filed under: files, duplicate

Offline

 

#9 2012-11-11 01:56:59 pm

adayzdone
Member
From:: New York
Registered: 2011-01-25
Posts: 525

Re: Duplicate: Finder vs System Events

If I get references or such through the UI of Finder, then I use Finder. If not, System Events.


But the point of the question is that because you can't send the duplicate command if you reference the files from System Events, you must reference them from Finder first.
The only System Events option that works is:

Applescript:

tell application "System Events" to duplicate finderFile to finderFolder

Offline

 

#10 2012-11-11 02:30:04 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5473

Re: Duplicate: Finder vs System Events

It seems that System Events's 'duplicate' command doesn't work with disk items. I haven't tried it with any other System Events objects.


NG

Offline

 

#11 2012-11-11 02:43:17 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1055

Re: Duplicate: Finder vs System Events

Nigel Garvey wrote:

That's to be expected if finderFile and finderFolder are Finder references. System Events has no idea what to do with them, so they're passed to their owner.


That's the way it works, but I don't know about the "expected" part. If it doesn't know what to do with what it's being fed, wouldn't it behoove System Events to supply an error?   wink

Offline

 

#12 2012-11-11 02:44:12 pm

McUsr
Member
From:: Southern Norway
Registered: 2010-04-07
Posts: 1776

Re: Duplicate: Finder vs System Events

smile
I did try a lot of things, and none worked!

I don't see any usefullness of this, but of course, if you know there is only this copy in that folder, since you duplicate to a folder, then maybe it is faster, on the other hand, you have to send events from Finder to system events, or maybe you pick up the finder references first, before you do something in a System Events block, which then sends it back to finder?

Amusing! big_smile

Last edited by McUsr (2012-11-11 02:45:50 pm)


Mercurial vcs is a joy to use for scripting.


Filed under: Finder

Offline

 

#13 2012-11-11 03:01:54 pm

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

Re: Duplicate: Finder vs System Events

duplicate is one of the tasks which I execute with do shell script because as Nigel wrote, it doesn't do its duty in System Events.

Yvan KOENIG (VALLAURIS, France) dimanche 11 novembre 2012 22:01:46

Offline

 

#14 2012-11-11 03:43:57 pm

adayzdone
Member
From:: New York
Registered: 2011-01-25
Posts: 525

Re: Duplicate: Finder vs System Events

I don't see any usefullness of this


duplicate is one of the tasks which I execute with do shell script because as Nigel wrote, it doesn't do its duty in System Events.


I was more interested in why the command performed as it does rather than the practicality of it. Thanks for everyone's input.

Offline

 

#15 2012-11-11 03:51:01 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5473

Re: Duplicate: Finder vs System Events

Marc Anthony wrote:
Nigel Garvey wrote:

That's to be expected if finderFile and finderFolder are Finder references. System Events has no idea what to do with them, so they're passed to their owner.


That's the way it works, but I don't know about the "expected" part. If it doesn't know what to do with what it's being fed, wouldn't it behoove System Events to supply an error?   wink


A trifle untidy to us purists, to be sure.  wink  But then a lot of people put things into 'tell' statements which shouldn't be there and their scripts often work. In this case, the references belong to the Finder and the Finder understands the 'duplicate' command, so it does the honours.

Another manifestation of this is the first commented-out command in adayzdone's original script, which isn't even in a 'tell' statement, but still works.

Last edited by Nigel Garvey (2012-11-11 03:52:19 pm)


NG

Offline

 

#16 2021-12-04 05:23:40 am

Joy
Member
From:: Tirol
Registered: 2008-07-04
Posts: 680

Re: Duplicate: Finder vs System Events

Sorry to resurrect this topic, but..

Applescript:

tell app "System events" to duplicate file hfsTxtFile to folder hfsTxtDesktop

.. This command seems broken. Why should a simple command like this one, stop to work?
File and destination are specified in hfs text format, System events just fails (Mojave)

I mean of course I can, but don't like to use the Finder or shell
Bash requires some extra work to deal with illegal characters and is longer than a simple "duplicate"

Offline

 

#17 2021-12-04 10:23:15 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1211

Re: Duplicate: Finder vs System Events

KniazidisR wrote:

I got into AppleScript 2 years ago, so I don’t know if this command worked like duplicate ever before. As I personally see it, this is the copy command these days:



KniazidisR is aware of this, but to avoid any confusion, the following is from the AppleScript Language Guide:

The copy command may be used to assign new values to existing variables, or to define new variables.... When using copy with an object specifier, the specifier itself is the value copied, not the object in the target application that it refers to. copy therefore copies the object specifier, but does not affect the application data at all. To copy the object in the target application, use the application’s duplicate command, if it has one.



The System Events duplicate command has never worked for me. The error message returned when using the System Events duplicate command is "Files can not be copied" and that does appear to be the case. It's a bit odd, though, that the System Events move command works as expected.

Anyways, Joy has ruled out use of the shell and ASObjC, which seems to leave Finder.

Last edited by peavine (2021-12-04 10:27:00 am)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#18 2021-12-04 10:47:26 am

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

Re: Duplicate: Finder vs System Events

For the move command we have this:

The following classes respond to the move command:

disk item    file    file package    property list file   
disk    alias    folder    XML file

It is very odd: no any information for the classes which respond to the duplicate command.

It seems that this command was planned to be implemented, but then it was abandoned, and in the dictionary developers forgot to indicate that the command is not working yet. And here we are racking our brains on what this command is doing... big_smile

Last edited by KniazidisR (2021-12-04 10:52:44 am)


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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)