System Events and Alias

I know I must be missing something really simple but can’t figure it out.

The following works fine:

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

But the following throws an error:

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

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

The error is:

In the second script I tried adding alias before theFile and theFolder without success. What am I doing wrong?

Hello peavine.

Which system are you running ?

Here, under 10.13.6, running

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

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

gave the history :


-- Don't click upon "Open this Scriplet in your Editor:", it's an history.

tell application "Script Editor"
	choose file
		--> alias "SSD 1000:Users:**********:Desktop:66382862_1_1 copie.pdf"
end tell
(*alias SSD 1000:Users:**********:Desktop:66382862_1_1 copie.pdf*)
tell application "Script Editor"
	choose folder
		--> alias "SSD 1000:Users:**********:Downloads:"
end tell
(*alias SSD 1000:Users:**********:Downloads:*)
tell application "System Events"
	move alias "SSD 1000:Users:**********:Downloads:66382862_1_1 copie.pdf" to alias "SSD 1000:Users:**********:Downloads:"
		--> file "SSD 1000:Users:**********:Downloads:66382862_1_1 copie.pdf"
end tell

Résultat :
file "SSD 1000:Users:**********:Downloads:66382862_1_1 copie.pdf" of application "System Events"

I’m really puzzled by what appears in this history.

The original file appears as :
(alias SSD 1000:Users::Desktop:66382862_1_1 copie.pdf)
but the move instruction is reported as :
move alias "SSD 1000:Users:
:Downloads:66382862_1_1 copie.pdf" to alias "SSD 1000:Users::Downloads:"
→ file "SSD 1000:Users:
**:Downloads:66382862_1_1 copie.pdf"

May be useful to get the permissions of the folder Download.

Here they are :

Résultat :
me : lecture et écriture (read & write)
everyone : Accès interdit (unauthorized access)

I got exactly what you got when I ran :

set theFile to (choose file)
log result
set theFolder to (choose folder with multiple selections allowed)
log result

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

It’s logical because in this case, theFolder isn’t an alias but, at best, a list of one alias.

→ error “Erreur dans System Events : Impossible de convertir {alias "SSD 1000:Users::Downloads:"} en type location specifier ou text." number -1700 from {alias "SSD 1000:Users::Downloads:”}

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 2 janvier 2020 23:49:46

Hi peavine.

The script works on my Mojave system. It looks from your error message as if Catalina’s System Events prefers its own specifiers as parameters for its commands.

Thanks Yvan and Nigel. I worked with this some more, testing it with varous folders and running it with Script Editor and Fastscripts, but I always receive the same result. I tried the following and System Events does recognize the alias:

tell application "System Events"
	alias "Macintosh HD:Users:bob:Working:New Text File.txt"
end tell --> alias "Macintosh HD:Users:bob:Working:New Text File.txt"

I also tried the duplicate command but got the same error message. So, it does appear that this is an issue only when an alias is used a specifier for a command and only on Catalina.

I am also getting an error in Catalina 10.15.2

FWIW, I see the same. So aliases are failing in System Events, Image Events, and Adobe apps, at the least. That sounds awfully like something outside the apps failing.

FWIW, System Events is still accepting «class furl».

That is not because of Catalina 10.15.2. Simply you can’t create System Events aliases from AppleScript aliases. But you can create them from HFS paths.

System Events has its own class of aliases, which doesn’t usual AppleScript aliases. So, to use its own aliases with System Events you should create them into the tell application “System Events” block. And this is not bug of Catalina. The Apple OS is designed this way:

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

tell application "System Events"
	move alias theFile to alias theFolder
	{alias theFile, alias theFolder}
end tell

NOTE: I added the result list, so you can see what is the System Event’s aliases. As you can see, theSystem Event’s aliases shows all its properties in the Script Debugger, but AppleScript aliases doesn’t show.

Here is System Event’s alias more clear code to understand what I say above:

set theFile to (choose file) as text

set appleScriptAlias to alias theFile

tell application "System Events" to set systemEventsAlias to alias theFile

see in the Script Debugger appleScriptAlias, than see systemEventsAlias. The first doesn’t show its properties

NOTE: System Events, can process directly AppleScript aliases as well as its own aliases.

As I am pig headed I made a new test after editing the code using with multiple selections allowed.

set theFile to (choose file)
log result
set theFolder to (choose folder with multiple selections allowed)
log result

tell application "System Events"
	move theFile to (item 1 of theFolder) -- EDITED 
end tell

This time, as it no longer pass a list of aliases but a single alias, it behaves flawlessly.



Don't click [Open this Scriplet in your Editor:],here is a Log History

tell application "Script Editor"
	choose file
		--> alias "SSD 1000:Users:**********:Desktop:aapart_taxe_habitation copie.pdf"
end tell
(*alias SSD 1000:Users:**********:Desktop:aapart_taxe_habitation copie.pdf*)
tell application "Script Editor"
	choose folder with multiple selections allowed
		--> {alias "SSD 1000:Users:**********:Desktop:ƒ Disques anciens:"}
end tell
(*alias SSD 1000:Users:**********:Desktop:ƒ Disques anciens:*)
tell application "System Events"
	move alias "SSD 1000:Users:**********:Desktop:aapart_taxe_habitation copie.pdf" to alias "SSD 1000:Users:**********:Desktop:ƒ Disques anciens:"
		--> file "SSD 1000:Users:**********:Desktop:ƒ Disques anciens:aapart_taxe_habitation copie.pdf"
end tell
Résultat :
file "SSD 1000:Users:**********:Desktop:ƒ Disques anciens:aapart_taxe_habitation copie.pdf" of application "System Events"

Using «class furl», it behaves well with :

set theFile to (choose file)
log result
set theFolder to (choose folder with multiple selections allowed)
log result

tell application "System Events"
	move theFile as «class furl» to (item 1 of theFolder as «class furl»)
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 3 janvier 2020 16:00:10

I ran Yvan’s script from Post #8, which uses «class furl», and it works fine. That’s very helpful.

Were you originally using "with multiple selections allowed ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 3 janvier 2020 16:59:49

So, you want to tell users that System Events cannot work with aliases, but only with furls?

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.