andrewp-as-is / applescript.py Goto Github PK
View Code? Open in Web Editor NEW:apple: :snake: run applescript
License: The Unlicense
:apple: :snake: run applescript
License: The Unlicense
I have a list of applescript files that I would love for it to be able to communicate with each other. I am thinking if the run command has an option to add args it would help a lot with my framework:
http://hints.macworld.com/article.php?story=20050523140439734
Let me know if this is something possible.
hi there,
Thanks for the excellent lib :)
I have a use case. I have a bash script (stored in the same directory as my python script) and I need to run that so it opens a terminal and runs the file. Similar with the shell script. The shell script does have some sudo
commands and I think the user would need to enter their sudo pwd hence I need the terminal opened up as well.
I was wondering if that's possible using something like applescript.tell.app('Terminal', 'fileName.sh')
or similar stuff?
Any help is greatly appreciated :)
Hello,
I'm using this wonderful lib in my program https://github.com/SimonIT/spotifylyrics to read the title of Spotify to detect the current playing song.
Everything works fine, until I try to distribute it via pyinstaller.
This is the command I use to generate the SpotifyLyrics.app:
https://github.com/SimonIT/spotifylyrics/blob/6ff9ed03ee431f9935c11bb3f19e94f1d600abcc/.travis.yml#L53
You can remove the -w
flag to see the following error message during executing the resulting executable:
Traceback (most recent call last):
File "SpotifyLyrics.pyw", line 14, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/usr/local/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "backend.py", line 27, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/usr/local/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "applescript/__init__.py", line 3, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/usr/local/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "only/__init__.py", line 48, in <module>
File "public/__init__.py", line 65, in add
IndexError: list index out of range
[15076] Failed to execute script SpotifyLyrics
Thanks for the lib! While trying it out, I cam across a bug / undocumented change introduced by 67948c7:
The replace line 13 of applescript/__init__.py
changes the default to the execution of Javascript:
-def run(applescript, background=False):
+def run(applescript, background=False, javascript=True):
This was unexpected / confusing for me and is not consistent with the examples stated in the README:
>>> import applescript
>>> r = applescript.run('return 1')
>>> r.code, r.out, r.err
(1, '', '0:8: syntax error: Error on line 1: SyntaxError: Return statements are only valid inside functions. (-2700)')
Without javascript
set to False
it works as expected:
>>> r = applescript.run('return 1', javascript=False)
>>> r.code, r.out, r.err
(0, '1', '')
I'm writing a library which execute a lot of small apple scripts, possible some 1000 in a single run.
I run into the exception
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1441, in _execute_child
errpipe_read, errpipe_write = os.pipe()
OSError: [Errno 24] Too many open files
I checked the library code and it looks that it opens a new temporary file for every single apple script execution and never close the file descriptor. Which after some 100 calls, results in this OS error.
Finally I used a different approach which did not use a temporary file but pipes the script via stdin to the osascript
It runs basically around the lines
proc = subprocess.Popen(["osascript", "-"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = proc.communicate(input=cmd.encode("utf-8"))
status = proc.returncode
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.