Giter VIP home page Giter VIP logo

applescript.py's People

Contributors

andrewp-as-is avatar goestav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

applescript.py's Issues

Can i use this lib to run bash/shell script files in terminal?

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 :)

Unable to use inside a pyinstaller package

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

applescript.run() defaults to javascript=True

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', '')

OSError: [Errno 24] Too many open files

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.