Reputation: 1833
I've created an AppleScript bundle - main.app
from
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
set cmnd to appAlias & "Contents/MacOs/MyApp &"
display dialog "You're going to launch" & cmnd buttons {"Ok"}
do shell script cmnd with administrator privileges
end run
MyApp.app
resides in main.app/Contents/Resources
When I launch main.app
it quits right after displaying dialog and asking username
and password
without starting MyApp.app
.
What am I doing wrong?
Upvotes: 0
Views: 1808
Reputation: 1833
There was a silly mistake in my script. I need to write "MacOS" instead of "MacOs" Here is the script which allows my application to create the files in the restricted area:
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
set cmnd to appAlias & "Contents/MacOS/MyApp"
display dialog "You're going to launch" & cmnd buttons {"Ok"}
do shell script cmnd with administrator privileges
end run
Upvotes: 0
Reputation: 11238
Try:
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
display dialog "You're going to launch" & appAlias buttons {"Ok"}
tell application "System Events" to open appAlias
end run
EDIT
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
display dialog "You're going to launch" & appAlias buttons {"Ok"}
do shell script "open " & quoted form of appAlias with administrator privileges
end run
Upvotes: 1
Reputation: 19032
One problem could be if there are any spaces in the path, then essentially the path will be incorrect. Therefore you should always use "quoted form of" to ensure spaces and other path characters are accounted for properly. Try this...
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
set cmnd to appAlias & "Contents/MacOs/MyApp"
display dialog "You're going to launch" & cmnd buttons {"Ok"}
do shell script (quoted form of cmnd & " &") with administrator privileges
end run
Also, I think you need to be certain of the name of the unix executable inside MyApp.app. Most applescript apps have "applet" inside instead of the name of the app. So double check that. You may need this instead...
set cmnd to appAlias & "Contents/MacOS/applet"
Upvotes: 3