Bring application to front by its path
up vote
1
down vote
favorite
How can I bring an application to front by its path?
i.e. Assume /Applications/MyApp.app
have already started; At a time I want to bring that MyApp.app window to front by passing its path to AppleScript: myApplScript.scpt /Applications/MyApp.app
.
I tried by this script, but this did not worked for me:
on run argv
set apppath to (item 1 of argv) as string
tell application "System Events"
set frontmost of every process whose path is apppath to true
end tell
end run
Thanks!
macos applescript
add a comment |
up vote
1
down vote
favorite
How can I bring an application to front by its path?
i.e. Assume /Applications/MyApp.app
have already started; At a time I want to bring that MyApp.app window to front by passing its path to AppleScript: myApplScript.scpt /Applications/MyApp.app
.
I tried by this script, but this did not worked for me:
on run argv
set apppath to (item 1 of argv) as string
tell application "System Events"
set frontmost of every process whose path is apppath to true
end tell
end run
Thanks!
macos applescript
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How can I bring an application to front by its path?
i.e. Assume /Applications/MyApp.app
have already started; At a time I want to bring that MyApp.app window to front by passing its path to AppleScript: myApplScript.scpt /Applications/MyApp.app
.
I tried by this script, but this did not worked for me:
on run argv
set apppath to (item 1 of argv) as string
tell application "System Events"
set frontmost of every process whose path is apppath to true
end tell
end run
Thanks!
macos applescript
How can I bring an application to front by its path?
i.e. Assume /Applications/MyApp.app
have already started; At a time I want to bring that MyApp.app window to front by passing its path to AppleScript: myApplScript.scpt /Applications/MyApp.app
.
I tried by this script, but this did not worked for me:
on run argv
set apppath to (item 1 of argv) as string
tell application "System Events"
set frontmost of every process whose path is apppath to true
end tell
end run
Thanks!
macos applescript
macos applescript
edited Nov 7 at 10:41
asked Nov 7 at 10:22
Santanu Karar
505517
505517
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
Usually, all you need to do is to activate
the application, which switches focus to it (even if the application is already running):
activate application "MyApp"
You can use this command directly with its path like this:
activate application "/Applications/MyApp.app"
or, in your specific case,
activate application apppath
although you shouldn't need to.
If that doesn't work, you can try System Events:
tell application "System Events" to set frontmost of process "MyApp" to true
or, using its path:
tell application "System Events" to set the frontmost of the first process ¬
whose POSIX path of application file is "/Applications/MyApp.app" to true
May be worth mentioning that to actually pass the path argument to the AppleScript via the command line run:$ osascript /path/to/myApplScript.scpt /Applications/myApp.app
- well that's what I assume the OP means by saying "by passing its path to AppleScript".
– RobC
Nov 7 at 14:10
However, my assumption of why the OP actually wants to use an AppleScript to bring an app to the front by it's path may be incorrect. As runningopen /Applications/myApp.app/
via the command line will achieve the same result.
– RobC
Nov 7 at 14:21
Thanks @CJK, the last one seems best fit for our needs and worked-out good! Thank you! On RobC's query, we ran/trigger 3rd party applications from our custom macOS application, sometime - a few triggered application turns to background (in display order) thus we execute an AppleScript passing the application's path and makes it bring to front (in display order).
– Santanu Karar
Nov 8 at 7:01
Sorry I forgot this ) ty
– Santanu Karar
Nov 8 at 7:08
add a comment |
up vote
-1
down vote
Have you tried checking for the open files for the process?
There are several ways of doing this (see: this article)
Normally the application binary will be an open file of the process.
Keep in mind that the binary executable may be contained in a package and you will need to look for it by doing a show package contents
in finder and then appending the path to the executable in the package. In the package check under /Contents/MacOs/
.
This might take a long time if you have many open processes and therefore not very practical to run often.
Also take into account that a single executable file can be running in more then one process instance.
A pity that the standard Activity Monitor is not scriptable with applescript which I just verified hoping for a more applescript friendly solution. You should still be able to achieve the same result via calling the shell command line.
Also often the process name is equal or similar to the filename but that depends on the application or process you're looking for.
I'm guessing you must have different versions of the same app installed that you need to check for the application by pathname?
Or if you don't need to figure out the path name dynamically you can simply look it up in advance using the Activity Monitor or on the command line. There you can identify the process name that corresponds to you your running application that was started from the specified path. Knowing the process name in advance then makes it easy and you can simply use
tell application "System Events" to get application process "Name of My Application"
--insert the actions you want to perform on your running app here
end tell
To solve any process uniqueness issues in case the same app is running more then once you can always result to the pid
or unix process Id. Here's an article on how to get the pid in applescript of a running app
I wanted to ignore 'name' based solution and that is why I asked this question ) But thank you for your thoughts!
– Santanu Karar
Nov 8 at 7:03
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Usually, all you need to do is to activate
the application, which switches focus to it (even if the application is already running):
activate application "MyApp"
You can use this command directly with its path like this:
activate application "/Applications/MyApp.app"
or, in your specific case,
activate application apppath
although you shouldn't need to.
If that doesn't work, you can try System Events:
tell application "System Events" to set frontmost of process "MyApp" to true
or, using its path:
tell application "System Events" to set the frontmost of the first process ¬
whose POSIX path of application file is "/Applications/MyApp.app" to true
May be worth mentioning that to actually pass the path argument to the AppleScript via the command line run:$ osascript /path/to/myApplScript.scpt /Applications/myApp.app
- well that's what I assume the OP means by saying "by passing its path to AppleScript".
– RobC
Nov 7 at 14:10
However, my assumption of why the OP actually wants to use an AppleScript to bring an app to the front by it's path may be incorrect. As runningopen /Applications/myApp.app/
via the command line will achieve the same result.
– RobC
Nov 7 at 14:21
Thanks @CJK, the last one seems best fit for our needs and worked-out good! Thank you! On RobC's query, we ran/trigger 3rd party applications from our custom macOS application, sometime - a few triggered application turns to background (in display order) thus we execute an AppleScript passing the application's path and makes it bring to front (in display order).
– Santanu Karar
Nov 8 at 7:01
Sorry I forgot this ) ty
– Santanu Karar
Nov 8 at 7:08
add a comment |
up vote
2
down vote
accepted
Usually, all you need to do is to activate
the application, which switches focus to it (even if the application is already running):
activate application "MyApp"
You can use this command directly with its path like this:
activate application "/Applications/MyApp.app"
or, in your specific case,
activate application apppath
although you shouldn't need to.
If that doesn't work, you can try System Events:
tell application "System Events" to set frontmost of process "MyApp" to true
or, using its path:
tell application "System Events" to set the frontmost of the first process ¬
whose POSIX path of application file is "/Applications/MyApp.app" to true
May be worth mentioning that to actually pass the path argument to the AppleScript via the command line run:$ osascript /path/to/myApplScript.scpt /Applications/myApp.app
- well that's what I assume the OP means by saying "by passing its path to AppleScript".
– RobC
Nov 7 at 14:10
However, my assumption of why the OP actually wants to use an AppleScript to bring an app to the front by it's path may be incorrect. As runningopen /Applications/myApp.app/
via the command line will achieve the same result.
– RobC
Nov 7 at 14:21
Thanks @CJK, the last one seems best fit for our needs and worked-out good! Thank you! On RobC's query, we ran/trigger 3rd party applications from our custom macOS application, sometime - a few triggered application turns to background (in display order) thus we execute an AppleScript passing the application's path and makes it bring to front (in display order).
– Santanu Karar
Nov 8 at 7:01
Sorry I forgot this ) ty
– Santanu Karar
Nov 8 at 7:08
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Usually, all you need to do is to activate
the application, which switches focus to it (even if the application is already running):
activate application "MyApp"
You can use this command directly with its path like this:
activate application "/Applications/MyApp.app"
or, in your specific case,
activate application apppath
although you shouldn't need to.
If that doesn't work, you can try System Events:
tell application "System Events" to set frontmost of process "MyApp" to true
or, using its path:
tell application "System Events" to set the frontmost of the first process ¬
whose POSIX path of application file is "/Applications/MyApp.app" to true
Usually, all you need to do is to activate
the application, which switches focus to it (even if the application is already running):
activate application "MyApp"
You can use this command directly with its path like this:
activate application "/Applications/MyApp.app"
or, in your specific case,
activate application apppath
although you shouldn't need to.
If that doesn't work, you can try System Events:
tell application "System Events" to set frontmost of process "MyApp" to true
or, using its path:
tell application "System Events" to set the frontmost of the first process ¬
whose POSIX path of application file is "/Applications/MyApp.app" to true
edited Nov 7 at 11:16
answered Nov 7 at 11:09
CJK
2,3471114
2,3471114
May be worth mentioning that to actually pass the path argument to the AppleScript via the command line run:$ osascript /path/to/myApplScript.scpt /Applications/myApp.app
- well that's what I assume the OP means by saying "by passing its path to AppleScript".
– RobC
Nov 7 at 14:10
However, my assumption of why the OP actually wants to use an AppleScript to bring an app to the front by it's path may be incorrect. As runningopen /Applications/myApp.app/
via the command line will achieve the same result.
– RobC
Nov 7 at 14:21
Thanks @CJK, the last one seems best fit for our needs and worked-out good! Thank you! On RobC's query, we ran/trigger 3rd party applications from our custom macOS application, sometime - a few triggered application turns to background (in display order) thus we execute an AppleScript passing the application's path and makes it bring to front (in display order).
– Santanu Karar
Nov 8 at 7:01
Sorry I forgot this ) ty
– Santanu Karar
Nov 8 at 7:08
add a comment |
May be worth mentioning that to actually pass the path argument to the AppleScript via the command line run:$ osascript /path/to/myApplScript.scpt /Applications/myApp.app
- well that's what I assume the OP means by saying "by passing its path to AppleScript".
– RobC
Nov 7 at 14:10
However, my assumption of why the OP actually wants to use an AppleScript to bring an app to the front by it's path may be incorrect. As runningopen /Applications/myApp.app/
via the command line will achieve the same result.
– RobC
Nov 7 at 14:21
Thanks @CJK, the last one seems best fit for our needs and worked-out good! Thank you! On RobC's query, we ran/trigger 3rd party applications from our custom macOS application, sometime - a few triggered application turns to background (in display order) thus we execute an AppleScript passing the application's path and makes it bring to front (in display order).
– Santanu Karar
Nov 8 at 7:01
Sorry I forgot this ) ty
– Santanu Karar
Nov 8 at 7:08
May be worth mentioning that to actually pass the path argument to the AppleScript via the command line run:
$ osascript /path/to/myApplScript.scpt /Applications/myApp.app
- well that's what I assume the OP means by saying "by passing its path to AppleScript".– RobC
Nov 7 at 14:10
May be worth mentioning that to actually pass the path argument to the AppleScript via the command line run:
$ osascript /path/to/myApplScript.scpt /Applications/myApp.app
- well that's what I assume the OP means by saying "by passing its path to AppleScript".– RobC
Nov 7 at 14:10
However, my assumption of why the OP actually wants to use an AppleScript to bring an app to the front by it's path may be incorrect. As running
open /Applications/myApp.app/
via the command line will achieve the same result.– RobC
Nov 7 at 14:21
However, my assumption of why the OP actually wants to use an AppleScript to bring an app to the front by it's path may be incorrect. As running
open /Applications/myApp.app/
via the command line will achieve the same result.– RobC
Nov 7 at 14:21
Thanks @CJK, the last one seems best fit for our needs and worked-out good! Thank you! On RobC's query, we ran/trigger 3rd party applications from our custom macOS application, sometime - a few triggered application turns to background (in display order) thus we execute an AppleScript passing the application's path and makes it bring to front (in display order).
– Santanu Karar
Nov 8 at 7:01
Thanks @CJK, the last one seems best fit for our needs and worked-out good! Thank you! On RobC's query, we ran/trigger 3rd party applications from our custom macOS application, sometime - a few triggered application turns to background (in display order) thus we execute an AppleScript passing the application's path and makes it bring to front (in display order).
– Santanu Karar
Nov 8 at 7:01
Sorry I forgot this ) ty
– Santanu Karar
Nov 8 at 7:08
Sorry I forgot this ) ty
– Santanu Karar
Nov 8 at 7:08
add a comment |
up vote
-1
down vote
Have you tried checking for the open files for the process?
There are several ways of doing this (see: this article)
Normally the application binary will be an open file of the process.
Keep in mind that the binary executable may be contained in a package and you will need to look for it by doing a show package contents
in finder and then appending the path to the executable in the package. In the package check under /Contents/MacOs/
.
This might take a long time if you have many open processes and therefore not very practical to run often.
Also take into account that a single executable file can be running in more then one process instance.
A pity that the standard Activity Monitor is not scriptable with applescript which I just verified hoping for a more applescript friendly solution. You should still be able to achieve the same result via calling the shell command line.
Also often the process name is equal or similar to the filename but that depends on the application or process you're looking for.
I'm guessing you must have different versions of the same app installed that you need to check for the application by pathname?
Or if you don't need to figure out the path name dynamically you can simply look it up in advance using the Activity Monitor or on the command line. There you can identify the process name that corresponds to you your running application that was started from the specified path. Knowing the process name in advance then makes it easy and you can simply use
tell application "System Events" to get application process "Name of My Application"
--insert the actions you want to perform on your running app here
end tell
To solve any process uniqueness issues in case the same app is running more then once you can always result to the pid
or unix process Id. Here's an article on how to get the pid in applescript of a running app
I wanted to ignore 'name' based solution and that is why I asked this question ) But thank you for your thoughts!
– Santanu Karar
Nov 8 at 7:03
add a comment |
up vote
-1
down vote
Have you tried checking for the open files for the process?
There are several ways of doing this (see: this article)
Normally the application binary will be an open file of the process.
Keep in mind that the binary executable may be contained in a package and you will need to look for it by doing a show package contents
in finder and then appending the path to the executable in the package. In the package check under /Contents/MacOs/
.
This might take a long time if you have many open processes and therefore not very practical to run often.
Also take into account that a single executable file can be running in more then one process instance.
A pity that the standard Activity Monitor is not scriptable with applescript which I just verified hoping for a more applescript friendly solution. You should still be able to achieve the same result via calling the shell command line.
Also often the process name is equal or similar to the filename but that depends on the application or process you're looking for.
I'm guessing you must have different versions of the same app installed that you need to check for the application by pathname?
Or if you don't need to figure out the path name dynamically you can simply look it up in advance using the Activity Monitor or on the command line. There you can identify the process name that corresponds to you your running application that was started from the specified path. Knowing the process name in advance then makes it easy and you can simply use
tell application "System Events" to get application process "Name of My Application"
--insert the actions you want to perform on your running app here
end tell
To solve any process uniqueness issues in case the same app is running more then once you can always result to the pid
or unix process Id. Here's an article on how to get the pid in applescript of a running app
I wanted to ignore 'name' based solution and that is why I asked this question ) But thank you for your thoughts!
– Santanu Karar
Nov 8 at 7:03
add a comment |
up vote
-1
down vote
up vote
-1
down vote
Have you tried checking for the open files for the process?
There are several ways of doing this (see: this article)
Normally the application binary will be an open file of the process.
Keep in mind that the binary executable may be contained in a package and you will need to look for it by doing a show package contents
in finder and then appending the path to the executable in the package. In the package check under /Contents/MacOs/
.
This might take a long time if you have many open processes and therefore not very practical to run often.
Also take into account that a single executable file can be running in more then one process instance.
A pity that the standard Activity Monitor is not scriptable with applescript which I just verified hoping for a more applescript friendly solution. You should still be able to achieve the same result via calling the shell command line.
Also often the process name is equal or similar to the filename but that depends on the application or process you're looking for.
I'm guessing you must have different versions of the same app installed that you need to check for the application by pathname?
Or if you don't need to figure out the path name dynamically you can simply look it up in advance using the Activity Monitor or on the command line. There you can identify the process name that corresponds to you your running application that was started from the specified path. Knowing the process name in advance then makes it easy and you can simply use
tell application "System Events" to get application process "Name of My Application"
--insert the actions you want to perform on your running app here
end tell
To solve any process uniqueness issues in case the same app is running more then once you can always result to the pid
or unix process Id. Here's an article on how to get the pid in applescript of a running app
Have you tried checking for the open files for the process?
There are several ways of doing this (see: this article)
Normally the application binary will be an open file of the process.
Keep in mind that the binary executable may be contained in a package and you will need to look for it by doing a show package contents
in finder and then appending the path to the executable in the package. In the package check under /Contents/MacOs/
.
This might take a long time if you have many open processes and therefore not very practical to run often.
Also take into account that a single executable file can be running in more then one process instance.
A pity that the standard Activity Monitor is not scriptable with applescript which I just verified hoping for a more applescript friendly solution. You should still be able to achieve the same result via calling the shell command line.
Also often the process name is equal or similar to the filename but that depends on the application or process you're looking for.
I'm guessing you must have different versions of the same app installed that you need to check for the application by pathname?
Or if you don't need to figure out the path name dynamically you can simply look it up in advance using the Activity Monitor or on the command line. There you can identify the process name that corresponds to you your running application that was started from the specified path. Knowing the process name in advance then makes it easy and you can simply use
tell application "System Events" to get application process "Name of My Application"
--insert the actions you want to perform on your running app here
end tell
To solve any process uniqueness issues in case the same app is running more then once you can always result to the pid
or unix process Id. Here's an article on how to get the pid in applescript of a running app
answered Nov 7 at 19:06
stepvda
246
246
I wanted to ignore 'name' based solution and that is why I asked this question ) But thank you for your thoughts!
– Santanu Karar
Nov 8 at 7:03
add a comment |
I wanted to ignore 'name' based solution and that is why I asked this question ) But thank you for your thoughts!
– Santanu Karar
Nov 8 at 7:03
I wanted to ignore 'name' based solution and that is why I asked this question ) But thank you for your thoughts!
– Santanu Karar
Nov 8 at 7:03
I wanted to ignore 'name' based solution and that is why I asked this question ) But thank you for your thoughts!
– Santanu Karar
Nov 8 at 7:03
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187517%2fbring-application-to-front-by-its-path%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown