(path to me) isn't returning the same path in El Capitan as it used to

I need help,

I wrote a script bundle a long time ago and it has worked for years until I updated to El Capitan. Now when I run the script from the editor I am getting “File not found” because path to me is returning the wrong path.

In my script bundle’s resources folder I have other supporting files the script uses.

property pathtoMe : ((path to me) as text)
property hiddenFilePath : (((path to me) as text) & “Contents:Resources:”)
property fileIcon : hiddenFilePath & “scripticon.icns”
property logOutput : hiddenFilePath & “_LogOutput.txt”
property sourceOutput : hiddenFilePath & “_sourceList.txt”
property sourceData : hiddenFilePath & “sourceDate.numbers”

Pre El Capitan, this worked… Path to me retuned MacHD:User:Spoon:Scripts:File.name and now it returns the path to the Script Editor.app and not the script I am running.

I’m running 10.11 GM, and path to me returns the path to the document – as long as the document has been saved. I believe that’s also how it behaved before.

What seems to be new is what is returned for scripts which were nevere saved.

Here, I got :
alias “Aluice_250:Users:me:Library:Autosave Information:Document Éditeur de script non enregistré.scpt
which as far as I remember is new.

After saving it as a script bundle I got :
alias “Aluice_250:Users:me:Desktop:Sans titre.scptd:”
which is what was returned for years.

Yvan KOENIG running El Capitan 10.11 in French (VALLAURIS, France) mercredi 30 septembre 2015 12:04:55

Looking at this some more… Something must have changed.

property pathtoMe : ((path to me) as text) //doesn’t seem to work

on run
set newPath to ((path to me) as text) //works as expected
display dialog pathtoMe
display dialog newPath
end run

It’s odd -

pathtoMe returns the wrong path (returns the path to script editor.app)

where if I set the path in script it returns the correct path.

I get the same behavior when I run your script under Yosemite 10.10.5

No change on this point, except perhaps your memory :wink:

May you explain why you need to define this property his way ?

From my point of view clean coding would be :

property pathToMe : missing value

on run
	set pathToMe to ((path to me) as text) --works as expected
	display dialog pathToMe
	display dialog (my forSee())
end run

on forSee()
	set newPath to pathToMe
	return newPath
end forSee

I would never rely on a code using path to me in the definition of a property.

My understanding is that at compile time your instruction define pathToMe as the path to the Editor. I repeat that it behaves this way in Yosemite too.

The alternate scheme :

property pathToMe : missing value

on run
set pathToMe to path to me
end run

defines it at first run so it grabs the correct path, even if you move the script on an other device.

As I wrote in an other thread I dislike storing a variable value in a property because it modify the file so GateKeeper is not satisfied. I would code this way :

script shared
	property pathToMe : missing value
end script
on run
	set pathToMe to ((path to me) as text) --works as expected
	set shared's pathToMe to pathToMe
	display dialog pathToMe
	display dialog (my forSee())
end run

on forSee()
	set newPath to shared's pathToMe
	return newPath
end forSee

Nothing is changed in the file itself when we run it so there is no problem with GateKeeper.
Of course, the properties are not permanent but I see no reason to make the one listed in your original message permanent.

I must add something.
My own memory was wrong. When I run my code under Yosemite it returns, exactly as it do in El Capitan
“SSD 500:Users:me:Library:Autosave Information:Document Éditeur de script non enregistré.scpt”

The volume name changed because the OSes are on two different units.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mercredi 30 septembre 2015 20:49:07

Two notes:

¢ NEVER EVER declare a relative path with the path to expression in a property. The path is evaluated at compile time and can cause unexpected behavior if the script is moved or copied to another machine.
Declaring the property with missing value and setting the proper value at run time is fine.

¢ path to has an optional parameter as text

(path to me as text)

which is less expensive than the explicit coercion

((path to me) as text)

Thanks Stefan

I was unaware of the given tip.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) mercredi 30 septembre 2015 23:07:46