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

  • Home
  • SEARCH
  • 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 921577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:53:32+00:00 2026-05-15T18:53:32+00:00

I am receiving this error when trying to execute applescript from my java application.

  • 0

I am receiving this error when trying to execute applescript from my java application. The code is as follows:

String script = "tell application \"Terminal\" to do shell script \"/System/Library/CoreServices/Menu\\ Extras/user.menu/Contents/Resources/CGSession -suspend\" ";
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("AppleScript");
engine.eval(script);

I get the following error:

Exception in thread "main" javax.script.ScriptException: Expected “"” but found unknown token.
    at apple.applescript.AppleScriptEngine.evalScript(Native Method)
    at apple.applescript.AppleScriptEngine.eval(AppleScriptEngine.java:342)
    at apple.applescript.AppleScriptEngine.eval(AppleScriptEngine.java:313)
    at myTestApp.Main.main(Main.java:25)

Thanks for your consideration.

  • 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-05-15T18:53:33+00:00Added an answer on May 15, 2026 at 6:53 pm

    A guess based on experience… Maybe the escaped space in the pathname is your show stopper.

    Try to call a script from a location where the path has no spaces or try to ‘double-escape’ the escaped space, like so:

    "tell application \"Terminal\" to do shell script \"/System/Library/CoreServices/Menu\\\\ Extras/user.menu/Contents/Resources/CGSession -suspend\" "
    

    A common reason for strange errors are those whitespaces in pathnames. So it was my first guess, that this causes trouble in your script. Then I remembered that sometimes we have to ‘escape escaped backslashes’. This article doesn’t explain, why it solved exactly your problem, but it shows how many backslashes may be needed…

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

Sidebar

Related Questions

Im receiving this error when trying to compile my code. $ g++ -o BangBangControlTest
I'm receiving this PHP error while trying to use the Normalizer class, specifically the
I'm receiving suddenly this error on a Win2003 Server Web Application: Microsoft VBScript runtime
I'm receiving this error when trying to see a report.
I'm trying to use this script (which extracts the domain from a URL): CREATE
I am trying to execute this code, import osgeo.ogr def findPoints(geometry, results): for i
I am receiving this error when trying to use RedirectToAction, can anyone offer any
i am receiving this error when trying to add user location. I have a
I'm receiving this error while trying to use apc_store() . I googled it and
I am receiving this error when trying to use Python Server Pages with Mod_Python

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.