System Events and Alias

I am not sure I understood you completely, but the above script is still not working for me.
It triggers the following error:
“System Events got an error: NSArgumentsWrongScriptError”

In my original script, I did not use “with multiple selections allowed”.

Just to clarify, I ran the following script:

set theFile to (choose file)
set theFolder to (choose folder)

tell application "System Events"
	move theFile to theFolder
end tell

The result was:

I ran the following and it worked without error:

set theFile to (choose file)
set theFolder to (choose folder)

tell application "System Events"
	move theFile as «class furl» to theFolder as «class furl»
end tell

The following also worked without error:

set theFile to (choose file) as text
set theFolder to (choose folder) as text

tell application "System Events"
	move file theFile to folder theFolder
end tell

Finally, the following–which is a slight variant of the preceding script–also works.

set theFile to (choose file)
set theFolder to (choose folder)

tell application "System Events"
	move file (theFile as text) to folder (theFolder as text)
end tell

If that is true then why using the script below I can collect info on those alises?
Alias are indeed recognised within the tell application “System Events” handler. Otherwise the get properties of theFile would have triggered an error.
It seems to me that move command is failing.

set theFile to (choose file)
set theFolder to (choose folder)

tell application "System Events"
	get properties of theFile --> it does work !
	get properties of theFolder --> it does work !
	move theFile to theFolder --> gives an error !
end tell

As Nigel Garvey sad, on some systems (as on Mojave) System Events can deal with AppleScript aliases directly. On others System Events want only its own aliases, and generally, its own file references. It seems, on the Catalina too. That is bad. Because you should use coercion.

I just wanted to show how to create System Events alias (on Mojave), and to make it clear why the error occurs. Although, there is little practical benefit from this, as Peavine noted.

Conclusion: So I’m right that I’m not switching to Catalina yet. Actually, I worked with Yosemite, El Capitan, Mojave. I did not find so many bugs in all taken together, as in High Sierra. I uninstalled it as quickly as possible. Catalina seems to be an even more raw product. All Mac OS X applications should work seamlessly with AppleScript aliases. This is the purpose of AppleScript aliases, and for this they were invented …

No, under Catalina, System Events is able to execute:
(1) move file (anAliasItem as text) to folder (anAliasFolder as text)
(2) move (anAliasItem as «class furl») to (anAliasFolder as «class furl»)

but it fails to execute:
(3) move anAliasItem to anAliasFolder

At this time we know also that it’s able to grab properties of anAliasItem.
It would be useful to test how it behaves upon such objects with the commands : delete, duplicate, exists, save.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 3 janvier 2020 20:57:26

I was more interested to learn this: I know that on some older systems the following code gives the desired result (on Mojave, which is new system, too). And on Catalina, System Events cannot even work with its own aliases, (as idicore reports):

set anAliasFile to (choose file)
set anAliasFolder to (choose folder)

tell application "System Events"
	set anAliasFile to alias (anAliasFile as text)
	set anAliasFolder to alias (anAliasFolder as text)
	move anAliasFile to anAliasFolder
end tell

Yvan. The delete, duplicate, and save commands all fail when used with alias specifiers under Catalina, and the error messages are as quoted in my above post. The exists command does work, though.

Thank you, it’s good to know.

It seems that it’s time to file a report because it resemble to a bug in the interpreter used for commands working upon two file/folder specifiers.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 3 janvier 2020 22:12:07

No. My point was that dealing with aliases seems to be a problem that’s cropping up in several places in 10.15, and that so far, all of them will accept a «class furl» instead. So if someone hits the problem in another app, it may be worth their trying «class furl» for a workaround.

You are right that System Events defines its own alias class, but it has also worked with normal aliases in all versions up to 10.15, so something has changed. If the problem was only in System Events, I’d be looking more closely at its own alias class, but the fact that it’s cropping up elsewhere makes me suspect the problem is somewhere else.

I installed the just-released macOS Catalina 10.15.3 and reran the tests in my first post in this thread. System Events still seems not to work reliably with aliases. The best workaround, as Yvan and Shane suggest, seems to be to use «class furl».

You can also use paths with System Events as plain text strings in many situations:

set f to (choose file) as text
set d to (choose folder) as text

tell application "System Events"
		move f to d
end tell

This works on Catalina with both HFS and posix paths for use with commands, but, of course, a string is still just a string so can’t yield any properties relating to file objects without using an object specifier or coercion.

I installed the just-released macOS Catalina 10.15.4 and reran the tests in my first post in this thread. System Events still seems not to work reliably with aliases. The best workarounds seem to be to use «class furl» or to coerce the alias to text. Yvan earlier summarized this as follows:

I did some additional testing and found that:

  • The move command doesn’t work with AppleScript or System Events aliases.

  • The duplicate command doesn’t work with AppleScript or System Events aliases.

  • The delete command works with System Events aliases but not with AppleScript aliases.

peavine,

This works on new Catalina? :


set aFileHFSPath to (choose file) as text
set aFolderHFSPath to (choose folder) as text

tell application "System Events"
	set anAliasFile to alias aFileHFSPath
	set anAliasFolder to alias aFolderHFSPath
	move anAliasFile to anAliasFolder
end tell

I just installed macOS 10.15.5–which was released earlier today–and System Events still doesn’t work with aliases under the circumstances detailed in post 1 and afterwards. If this issue hasn’t been fixed by now it probably won’t be, so I’ll give up on this.

We know Apple’s answer: “it’s not a bug, it’s a deliberate feature” :rolleyes:

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 27 mai 2020 04:16:46

In vain they just fanned this whole story. When I published post #24 on this topic, I didn’t have Catalina yet. Now I have Catalina and I can perfectly read the expected parameters for the move command from the System Events dictionary:

disk item, list of disk iems, text, list of texts

This suggests a thought: is it not better and more efficient to use coercion in the text, and not in the furl class. In the case the furl class won’t work in the future either. I think it’s better to follow the dictionary paradigm anyway:


set aFileAlias to choose file
set aFolderAlias to path to desktop

tell application "System Events"
	move (aFileAlias as text) to (aFolderAlias as text)
end tell

I recently came across this old post after running into a problem directly related to the topic discussed. My intent was to perform keyed selection of a System Events process using an AppleScript file alias as the key and the System Events application file property value (i.e., the System Events file alias) as the value to be searched. From the current discussion, I learned that my searches were failing because System Events and AppleScript file aliases, although identical in external appearance, are values of two different classes. I wanted to share a method that efficiently converts System Events file aliases to AppleScript file aliases. Among other uses, this conversion enables keyed selection of a System Events process via its AppleScript file alias.

A direct method of performing this conversion is via the as «class furl» coercion described by Shane Stanley:

property systemEventsAliases : missing value
property appleScriptAliases : {}
tell application "System Events" to set my systemEventsAliases to application file of processes
repeat with currSystemEventsAlias in my systemEventsAliases
	set end of my appleScriptAliases to currSystemEventsAlias as «class furl» as alias
end repeat
return my appleScriptAliases

An alternative approach that executes 5x faster on my machine than the above method consists of the following steps: (1) utilizes the forced error message technique to get a text representation of the list of System Events file aliases, (2) modifies the text representation such that it takes on the text representation of a list of corresponding AppleScript file aliases, (3) recovers the list of AppleScript aliases by run script-ing the modified text representation:

tell application "System Events" to set systemEventsAliases to application file of processes
try
	|| of systemEventsAliases
on error m
end try
set tid to AppleScript's text item delimiters
try
	set AppleScript's text item delimiters to "{"
	set m to "{" & (m's text items 2 thru -1) -- removes any text preceding the outer left curly bracket
	set AppleScript's text item delimiters to "}"
	set m to "" & (m's text items 1 thru -2) & "}" -- removes any text following the outer right curly bracket
	set AppleScript's text item delimiters to " of application \"System Events\""
	tell (m's text items)
		set AppleScript's text item delimiters to ""
		set m to it as text -- removes the expression " of application "System Events" that ends each System Events file alias's text representation
	end tell
end try
set AppleScript's text item delimiters to tid
set appleScriptAliases to run script m -- transforms the text representation into a list of AppleScript file aliases
return appleScriptAliases
2 Likes

It was me who noticed that AppleScript aliases and System Events aliases are 2 completely different classes, although they are written in the same way.

Thank you for your last post, because it can be useful in some cases and because you are one of the few who got me exactly right.

Your comment …System Events has its own class of aliases… pointed out the underlying problem and also suggested a solution. I am very grateful to have found this helpful information. It resolved a lot of frustration and head-banging that I was going through.

This thread has become a bit involved. I thought I would summarize the underlying issue as explained in post 1, and approaches that resolve the issue on my Ventura computer.

In older versions of macOS, system aliases could be used with System Events commands, but that is no longer the case. The move command is an example:

set theFile to (choose file)
set theFolder to (choose folder)
tell application "System Events"
	move theFile to theFolder
end tell
--> System Events got an error: Can’t make alias "Macintosh HD:Users:Robert:Working:Test.txt" into type specifier.

The delete command is another example:

set theFile to (choose file)
tell application "System Events"
	delete theFile
end tell
--> System Events got an error: Can’t make alias "Macintosh HD:Users:Robert:Working:Test.txt" into type disk item.

Various approaches have been suggested to resolve this issue. These include coercing the system alias to a file object and using HFS and POSIX paths. All of these work on my Ventura computer:

-- coerce alias to «class furl»
set theFile to (choose file) as «class furl»
set theFolder to (choose folder) as «class furl»
tell application "System Events"
	move theFile to theFolder
end tell -- works as expected

-- make alias into HFS path
set theFile to (choose file) as text
set theFolder to (choose folder) as text
tell application "System Events"
	move theFile to theFolder
end tell -- works as expected

-- make alias into POSIX path
set theFile to POSIX path of (choose file)
set theFolder to POSIX path of (choose folder)
tell application "System Events"
	move theFile to theFolder
end tell -- works as expected

The above approaches cannot be used to get the properties of a file, and alias and file objects have to be used instead. For example,

set theFile to (choose file)
tell application "System Events"
	set fileKind to kind of theFile --> "text"
	set fileKind to kind of file (theFile as text) --> "text"
end tell

BTW, in older versions of macOS, the System Events dictionary stated that the duplicate command had not yet been implemented. That’s no longer the case in Ventura, but the duplicate command doesn’t work in my testing.