rdhyee / py-applescript

An easy-to-use Python wrapper for NSAppleScript, allowing Python scripts to communicate with AppleScripts and AppleScriptable applications.
Creative Commons Zero v1.0 Universal
140 stars 7 forks source link

Fixed incorrect NSURL method call #1

Closed indigodomo closed 6 years ago

indigodomo commented 6 years ago

NSURL.URLWitheFilePath doesn’t exist so you can’t load an AppleScript from a file. The correct call is NSURL.fileURLWithPath. Also bumped the version number to 1.0.1. I’ll leave it up to the original repo owner to push it up to pypi.

rdhyee commented 6 years ago

Thanks, @indigodomo, for creating this PR. I deeply appreciate your effort. I can confirm the original bug and that your fix works for me.

BTW, I find how you're using py-applescript to be instructive too: Indigo Domotics Blog

I don't control py-applescript on pypi. I'm guessing that it might be @hhas.

hhas commented 6 years ago

Hi Raymond, happy to turn over project ownership. I just tried adding “rdhyee” (from pypi.python.org/pypi/rdhyee_utils) as py-applescript owner on PyPI but it fails with error: “No user found with that username.” Please check your PyPI account is working or let us know your correct user name if that’s not it. Ditto to @indigodomo.

ETA: If your AppleScripts are embedded, another solution is to avoid NSAppleScript/OSAKit completely and use the AppleScript-ObjC bridge to expose your AppleScript handlers directly to PyObjC (appscript.sourceforge.net/asoc.html).

rdhyee commented 6 years ago

@hhas Thanks for trying to add me as an owner on PyPi. I don't know why adding to "rdhyee" doesn't work. I just logged into PyPi as rdhyee. Maybe I should contact PyPi support to find out what's happening.

Do you recommend the AppleScript-ObjC approach over using py-applescript?

hhas commented 6 years ago

Seems to have worked today (transient PyPI bug yesterday?). Py-applescript is now yours to do with as you will; once you're happy just remove me as an owner to confirm full transfer.

Re. ASOC, it needs a folder of .scpt file[s] to work (NSAppleScript allows you to compile from source as well as load .scpt files) and you need to wrap your AS handlers in script objects per-ASOC/Cocoa conventions, so it's not really appropriate for running user-supplied scripts†. OTOH, for running embedded scripts it provides about the same level of bridging as py-applescript without introducing a third-party dependency.

Personally I wouldn’t waste any time rewrite existing scripts (ain’t broke; don’t fix). For new projects I’d tend to ASOC as it works out the box, but for Python at least it’s as much a matter of personal preference. (For other languages, which don’t have high-level py-applescript style wrappers, ASOC is definitely the easiest route.) As with all things AE/OSA/AS: YMMV, Caveat Emptor, #MaintenanceModeWare, etc.

Cheers and best of luck.

(†Though neither is NSAppleScript as it runs everything in-process, which is really not the safest when it can access every Cocoa API. Use NSUserAppleScriptTask to execute user-supplied scripts if you can; it’s a lot more sandbox-friendly too.)

indigodomo commented 6 years ago

Raymond, have you had a chance to look at this? I'd really like to see the change pushed up to pypi so I can tell users that pip install will get them the right version. Thanks!

rdhyee commented 6 years ago

@indigodomo I've not had a chance to act on updating pypi. To be honest, I'm a bit rusty -- but I can take a look tomorrow. In addition, I can give you privileges on PyPi for this repo so that you can update PyPi. I'm guessing you're more up to speed on py-applescript than I am at the moment.

indigodomo commented 6 years ago

Honestly, I've never added or managed anything on PyPi either so I'm even more rusty than you. I appreciate your efforts!

rdhyee commented 6 years ago

@indigodomo OK, I'll take a shot and updating the PyPi repo tomorrow and hopefully, it'll be fine.

rdhyee commented 6 years ago

@indigodomo I think I've managed to update PyPI -- see https://pypi.python.org/pypi/py-applescript now.

@hhas I've also removed you as an owner on the project on PyPI as requested. Thanks so much for writing py-applescript in the first place and for your insights on this PR!

indigodomo commented 6 years ago

Excellent news @rdhyee. I just installed with pip, loaded a script from a file, and successfully ran it. Looks like you got it. Thanks!