Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Run Osascript with QT
QtWS25 Last Chance

Run Osascript with QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
osascript qprocss apple
2 Posts 2 Posters 240 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Oreonan
    wrote on last edited by
    #1

    Hi,
    I'm currently trying to run an apple script via Osascript in a QT app.
    Here is my code:
    QString aScript =
    "on isVoiceOverRunning()\n"
    " set isRunning to false\n"
    " tell application quot;System Eventsquot;\n"
    " set isRunning to (name of processes) contains quot;VoiceOverquot;\n"
    " end tell\n"
    " return isRunning\n"
    "end isVoiceOverRunning\n"
    "on isVoiceOverRunningWithAppleScript()\n"
    " if isVoiceOverRunning() then\n"
    " set isRunningWithAppleScript to true\n"
    " tell application quot;VoiceOverquot;\n"
    " try\n"
    " set x to bounds of vo cursor\n"
    " on error\n"
    " set isRunningWithAppleScript to false\n"
    " end try\n"
    " end tell\n"
    " return isRunningWithAppleScript\n"
    " end if\n"
    " return false\n"
    " end isVoiceOverRunningWithAppleScript\n"
    " set msg to %1\n"
    " if isVoiceOverRunningWithAppleScript() then\n"
    " tell application quot;VoiceOverquot;\n"
    " output msg\n"
    " end tell\n"
    " else\n"
    " say msg\n"
    " end if\n";
    QString osascript = "/usr/bin/osascript";
    QStringList processArguments;
    processArguments << "-l" << "AppleScript";
    QProcess p;
    p.start(osascript, processArguments);
    p.write(aScript.arg(msg).toUtf8());
    p.closeWriteChannel();

    When I run my app in console, I have the following error:
    "QProcess: Destroyed while process ("/usr/bin/osascript") is still running."
    And my script is not running.
    Have you an idea of my mistake?
    Thanks in advance.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Oreonan said in Run Osascript with QT:

      Have you an idea of my mistake?

      As the warning message already tells you you destroy the QProcess instance before the application you want to execute is finished. Read the docs and don't destroy the QProcess until you get the QProcess::finished() signal.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved