Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8381807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:46:45+00:00 2026-06-09T16:46:45+00:00

Trying to run the following test.command script on Mac with a double-click. (requirement: MUST

  • 0

Trying to run the following test.command script on Mac with a double-click. (requirement: MUST be run with a double-click)

#!/bin/sh
sudo java -jar ExecutableJar.jar

Here is the output. (The terminal stays open with the below message)

Last login: Mon Aug 13 15:59:05 on ttys001
/Applications/Application\ Folder/test.command ; exit;
code-mac:~ code$ /Applications/Application\ Folder/test.command ; exit;
Unable to access jarfile ExecutableJar.jar
logout

[Process completed]

When I run the same command from Terminal…

sudo java -jar ExecutableJar.jar

…it works fine and opens the executable jar as expected (after prompting for my password). Any ideas? Also, if possible, I’d like the script to either not open a terminal at all, or at the very least close the terminal after starting the executable jar.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:46:46+00:00Added an answer on June 9, 2026 at 4:46 pm

    Adding the following to the beginning of the script made it work as expected when double-clicked.

    cd "$(dirname "$0")"
    

    The entire test.command script is as follows:

    #!/bin/sh
    cd "$(dirname "$0")"
    sudo java -jar ExecutableJar.jar &
    

    Adding the & at the end of the sudo command makes that executable jar run as a background process and allows further commands after the sudo to be processed, in my case, to close the Terminal window. (Otherwise it stays open)

    Lastly, adding either of the following to the end of the script will close it once it’s done. The first approach closes all Terminal windows and is a bit of an overkill, but it gets the job done.

    killall Terminal
    

    The second will prompt the user to close the Terminal window, giving the user the choice.

    osascript -e 'tell application "Terminal" to quit'
    

    A final, important note is that neither closing technque would work for my case. Since my script requires a sudo and prompts the user to enter their password, using either route prompted the user to close the Terminal (osascript) or closed the Terminal (killall) before the user had the chance to enter their password. In order to ask for the password first and then run the executable jar, use:

    sudo -v
    

    to prompt for the password if needed, then run the executable jar in the background with & and use killall or osascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to run a junit test I get the following error - java.lang.ClassCastException:
Trying to run the following command in php to run powershell command... the following
I'm trying to run the following PowerShell script to create a local user. This
I'm trying to run a test script using crontab within Plesk. The php file
I am using PowerShell and am trying to run the following command: .\test_cfdp.exe <
I am trying to Run Shell script in Cygwin but I am getting Following
I am trying to run my first Java program, an example script that interacts
I have a test script test.sh where I am trying to print out command
I am trying to run android instrumentation Junit test using command line.I am using
When I'm trying to run test.sh script I've always receive error from curl: curl:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.