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
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.
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.
This runs a trifle faster than your second script on my older hardware:
tell application "System Events" to ¬
set appRefList to POSIX path of application file of processes
repeat with thePath in appRefList
set contents of thePath to (contents of thePath as «class furl») as alias
end repeat
My apologies to peavine. I was excited to find a solution to the aggravating problem resulting from the System Events alias class differing from the AppleScript alias class, but I should have published it in a separate thread.
ccstone, your script runs 1.4x faster on my machine as well, and it’s a far more concise and elegant way of generating AppleScript aliases than mine. Thank you for sharing it.
Also note that if there is only one Posix path (not a list), the solutions from @bmose and @ccstone won’t work. You can check this by, for example, replacing application file of processes with application file of process “Finder”.
This can be easily fixed by applying an explicit coercion to the list. Let’s take for example the @ccstone script.
.
tell application "System Events" to set appRefList to (POSIX path of application file of process "Finder") as list -- EDITED
repeat with thePath in appRefList
set contents of thePath to (contents of thePath as «class furl») as alias
end repeat
if (count of appRefList) > 1 then return appRefList -- ADDED
return item 1 of appRefList -- ADDED
.
More practical example:
.
tell application "System Events" to set appRefList to (POSIX path of application file of 1st process whose name is "Finder") as list -- EDITED
repeat with thePath in appRefList
set contents of thePath to (contents of thePath as «class furl») as alias
end repeat
if (count of appRefList) > 1 then return appRefList -- ADDED
return item 1 of appRefList -- ADDED
.
Comment:
Anyway, this is all a digression from the original problem posed by @peavine in the thread - how to move the alias inside the System Event’s tell block. Apparently, coercion is indispensable, and such a solution is shown by @peavine in post #13 (scripts 1 and 4).