Finder objects references with System Events

Hi, I’m trying to run this:


tell application "System Events"
	set a to (application file "TextEdit" of folder "Applications" of disk "SISTEMA") as alias
	set p to POSIX path of a
	set f to (POSIX file p) as alias
end tell

return f

But seems don’t work.

if i replace “System Events” by “Finder” all work correctly. Why?

Thanks!

For System Events, application file is a property of a process so it’s not relevant here.
Looking in the System Events dictionary, everybody may read :

folder‚n [inh. disk item > item] : A folder in the file system
elements
contains aliases, disk items, files, file packages, folders;

If I understand well your problem here is a piece of code doing the job the clean way.

tell application "System Events"
	set a to path of disk item "TextEdit.app" of folder "Applications" of disk "Macintosh HD"
end tell
set p to POSIX path of a
set f to (POSIX file p) as alias
return f

As you may see, it don’t speak to System Events to trigger the functions POSIX path and POSIX path because both belong to the OSAX named Standard Additions and Apple warn us since Mac OSX 10.5 that speaking to OSAXens in a tell application block is a wrongdoer.

This said, we may achieve you goal with less code.

tell application "System Events"
	set a to path of disk item "TextEdit.app" of folder "Applications" of disk "Macintosh HD"
end tell
set f to a as alias
return f

or, for lazy guys like me,

tell application "System Events"
	set a to path of disk item "TextEdit.app" of folder "Applications" of disk "Macintosh HD"
end tell
return a as alias

Yvan KOENIG (VALLAURIS, France) lundi 13 octobre 2014 14:19:56

Thanks for your great reply!!

Let’s try being even lazier…


set tePath to POSIX path of (path to application id "com.apple.TextEdit")

:cool:

As I am even more lazy, I take care to the original code which returned an alias and code :

return path to application id "com.apple.TextEdit"

I add a huge thank you because I forgot that application id “com.apple.Textedit” is supposed to return the application object according to it’s real name.
In fact I know why I forgot that. If I run this script on my machine

set theApp to "Numbers 09"
id of application theApp
log result
tell me to get path to application theApp

set theToy to "Numbers"
id of application theToy
log result
tell me to get path to application theToy

the event log is :

(*com.apple.iWork.Numbers*)
tell application "Numbers 09"
	path to current application
		--> alias "SSD 500:Applications:iWork '09:Numbers 09.app:"
end tell
(*com.apple.iWork.Numbers*)
tell application "Numbers"
	path to current application
		--> alias "SSD 500:Applications:iPlay '13:Numbers.app:"
end tell

Yes, two different applications, a true one and a toy, share the same id.

Yvan KOENIG (VALLAURIS, France) mardi 14 octobre 2014 16:25:39

You can also have multiple copies of any app. But asking for the path via id should return the path to the copy that will be launched if you double-click on a document from that app.

Hello Shane

I knew that.

My problem is to force the system to launch the applications, not the toys, when I open “old & serious” documents.
I must have the two sets of products to be able to answer to questions which I receive.
At this time, I keep the toys in a disk image so when I double click a document, it’s treated by the applications.
When I must launch one of the toys, I mount the disk image.
It’s a bit boring but I didn’t found a better protocol.
From my point of view, it would be better to be free to set a different opener for documents created with different major versions.
Keynote 09, Numbers 09 and Pages 09 for “old & serious” documents,
Keynote 13, Numbers 13 and Pages 13 for docs created with these toys.
At this time I found no way to do that.

Yvan KOENIG (VALLAURIS, France) mercredi 15 octobre 2014 11:58:12

Yes, I understand that. I was pointing it out more for the original poster.

And who knows what will happen to the toys in the near future…

I try to be optimistic too but at this time I have to use the existing products.

Just an example of missing feature : how applications designers may imagine a word processor in which text boxes can’t be linked ?

Yvan KOENIG (VALLAURIS, France) mercredi 15 octobre 2014 14:11:10

I have the same issue with QuarkXPress where some workstations need 4 different major version. QuarkXPress uses the same name and same application id through all versions. So I work with paths:

tell application "/Applications/QuarkXPress 8/QuarkXPress.app"

end tell

Then I’m not only sure the right application is launched but also the right application receives the events.

Hello DJ

Of course, it’s what I use when I want to apply a script to a given document but, as Shane wrote about the default opener application, I detailed my problem with this feature.
Life would be easier if double clicking an “old & serious” document open this one with the tool belonging to iWork 09
and double clicking a recent one open it with a toy belonging to iToy 13.
In real life, when I select an old file, press cmd + i, select Numbers 09.app (2.3) as opener and click [ Tout modifier. ] ( maybe [ Change All. ] in English) this S.O.B. of system reset the default opener to Numbers.app (3.2.2).

Even if the more recent product was better than the old one (which in the given case is far from true) I would be glad to decide by myself which is the default opener.
At least, the situation is not catastrophic, when I open an old document with a toy, the applied changes aren’t autosaved but don’t repeat that, the engineers would be able to change this behavior :wink:

Yvan KOENIG (VALLAURIS, France) mercredi 15 octobre 2014 17:33:43