web-dev-qa-db-fra.com

Comment lancer une application AppleScript et exécuter des scripts Shell à partir d'un autre AppleScript?

Voici mes fichiers:

launcher.applescript

tell application ":path:to:applescript:apps:Shell-script-launcher.app" to launch

Shell-script-launcher.app [AppleScript, enregistré en tant qu'application]

 do Shell script "say starting script"

Comportement désiré:

  1. Exécutez "launcher.applescript" à partir de l'éditeur AppleScript
  2. Écoutez le "script de départ"

Comportement actuel:

  1. L'exécution du "Shell-script-launcher.app" en l'ouvrant manuellement dans le Finder donne le comportement attendu
  2. L'exécution de "launcher.applescript" ouvre le fichier "Shell-script-launcher.app" mais n'exécute jamais le script Shell.

J'ai essayé d'enregistrer l'application en tant que "Run Only" ainsi que "Stay Open". Toujours pas de progrès. Que recommandez-vous. Le résultat final doit être une application au lieu d'un AppleScript.

9
Ryan

Avez-vous essayé open ?

do Shell script "open 'path/to/applescript/apps/Shell-script-launcher.app' && say starting script"
4
user309603

Applescript a la commande "exécuter le script". Cela fonctionne sur les applications ou les applications applescript. Donc, si j'ai votre application sur mon bureau, cela fonctionne ...

set appPath to (path to desktop as text) & "Shell-script-launcher.app"
run script file appPath
4
regulus6633

Mettez-le entre "essayer" des mots-clés.

try
tell application ":path:to:applescript:apps:Shell-script-launcher.app" to activate
end try
1
atonus

Enregistrez votre script en tant qu’application . Ajoutez le script souhaité dans le dossier Script (voir le chemin ci-dessous)

Exécutez comme suit, modifiez le type de script que vous souhaitez exécuter ...

property theApplicationPath : the path to me as text <br/>
property theShellScriptPath : theApplicationPath & "Contents:Resources:Scripts:test.command"<br/>
property theShellScript : the quoted form of POSIX path of theShellScriptPath<br/>
<br/>
tell application "Terminal" to (do Shell script "/bin/bash " & theShellScript)
<br/>

Boom, Bob est ton oncle! Au moins pour moi.

1
HIram Newton

C’est très simple, il suffit d’utiliser le do Shell script normal, par exemple: 

do Shell script "open " & ¬
    quoted form of POSIX path of ¬
    alias ":path:to:applescript:apps:Shell-script-launcher.app"
1
Michael Sanders

Cela peut être utile, mais je ne suis pas un expert sur ce sujet. Dans ce cas, j’ai trouvé le comportement de double lancement (sur Yosemite, je n’ai utilisé aucune autre version d’OS X) très gênant et en fouillant, j’ai trouvé qu’on pouvait vérifier s’il fonctionnait déjà.

Ce script permet de lancer un nouveau terminal à tout moment.

if application "Terminal" is running then
    tell application "Terminal"
        activate
        do script ""
    end tell
else
    tell application "Terminal" to activate
end if
0
Peter Shannon