Wywołanie AppleScript z Pythona bez użycia osascript lub appscript?
Czy jest jakiś sposób na wykonanie (i uzyskanie wyników) kodu AppleScript z Pythona bez użycia osascript
narzędzia wiersza poleceń lub appscript (którego tak naprawdę nie chcę używać?) ponieważ nie jest już rozwijany/wspierany / zalecany)?
Uzasadnienie: w kolejne pytanie, które właśnie napisałem , opisuję dziwne/niepożądane zachowanie, którego doświadczam przy uruchamianiu AppleScript przez osascript
. Jak to właściwie nazywam ze skryptu Pythona, to zastanawiałam się, czy istnieje sposób na obejście osascript
w ogóle, ponieważ wydaje się, że tam leży problem-ale appscript (oczywisty wybór?) wygląda teraz na ryzykowne...
13
2 answers
Możesz użyć mostu PyObjC:
>>> from Foundation import *
>>> s = NSAppleScript.alloc().initWithSource_("tell app \"Finder\" to activate")
>>> s.executeAndReturnError_(None)
21
Author: Ken Thomases,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-28 04:34:27
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-28 04:34:27
PyPI jest twoim przyjacielem...
Http://pypi.python.org/pypi/py-applescript
Przykład:
import applescript
scpt = applescript.AppleScript('''
on run {arg1, arg2}
say arg1 & " " & arg2
end run
on foo()
return "bar"
end foo
on Baz(x, y)
return x * y
end bar
''')
print(scpt.run('Hello', 'World')) #-> None
print(scpt.call('foo')) #-> "bar"
print(scpt.call('Baz', 3, 5)) #-> 15
20
Author: foo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-19 09:36:14
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-19 09:36:14