Use Applescript Editor to write Python?

Discussion in 'Mac Programming' started by VideoBeagle, Oct 12, 2014.

  1. VideoBeagle macrumors 6502a

    Joined:
    Aug 17, 2010
    Location:
    App Q&A testing by request.
    #1
    I've seen there is a way to use Applescript Editor as a python IDE.

    Anyone know how this is done?

    (see attached pic).

    It's from a Coursera Python class I'm taking..just screen shots to show you installed the program (intro course). Peer grading...it's anonymous, so I can't ask the person who's screen it is how she did it (well, in a shot of her terminal, she left her whole name, so I could likely find her, but I'd like to avoid being too stalkery if i can :).
     

    Attached Files:

  2. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    Your screenshot just shows a regular AppleScript - print is a valid command, although in this case it will throw an error when run because the string is not a valid file path. I haven't seen any plugins, so as far as I know, the AppleScript Editor will only run AppleScripts.

    You can use other text editors such as TextWrangler to manage projects and run Python scripts directly from the editor (or from the Terminal) using your installed version.
     
  3. VideoBeagle thread starter macrumors 6502a

    Joined:
    Aug 17, 2010
    Location:
    App Q&A testing by request.
    #3
    Hmm..You know...I tested it on my Script Editor, got the expected errors, and thought to myself "Well it must be working as she doesn't have the errors, and that's a long way to go to not install TextWrangler (which is the recommended editor for the class)." I didn't notice she hadn't actually hit run in the screen shot.

    Yeah, my google searching came out zilch. I use TextWrangler already for the little python stuff I know, but I've always liked AppleScript's color coding and layout, and if there was away to get it to work with Python, that'd be great. Guess not :/
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    If AppleScript Editor were really interpreting Python, then the little popup menu that shows "AppleScript" next to "<No selected element>" wouldn't be showing "AppleScript". It'd be showing some other language, like, well, "Python".

    Theoretically, there can be dialects or languages other than plain ordinary AppleScript. I think these are called something like "OSA Language components". For example, googling osa language finds this:
    http://en.wikipedia.org/wiki/JavaScript_OSA
    which is basically JavaScript with some OSA inter-process stuff.

    It's not a standalone OSA language component (I think), but I think those are possible (or were at some point in time). I don't recall any names, since alternate OSA languages tend to be niche products. Nor do I recall if another component is needed in order for AppleScript Editor to use the alternate OSA language.

    See here for some details:
    https://developer.apple.com/library...ipt/conceptual/applescriptx/concepts/osa.html
     
  5. VideoBeagle thread starter macrumors 6502a

    Joined:
    Aug 17, 2010
    Location:
    App Q&A testing by request.
    #5
    YEah...I got snookered.

    (Anyone know a more..color coding set syntaxing type editor for Python, other than IDLE or TextWrangler.)
     
  6. hhas macrumors regular

    Joined:
    Oct 15, 2007
    #6
    OSA is a plugin mechanism for scripting language interpreters. In theory, an OSA-aware application can load and run scripts written in any scripting language, as long as an interpreter for that language has been packaged as a C-based Component Manager component. CM was basically the classic Mac equivalent to Windows' COM, commonly used for Quicktime codecs plugins and other dynamically loaded code bundles, though it's pretty much been superseded by NSBundles and ObjC classes.

    In practice, however, AppleScript is the only OSA language that has ever been good enough for production use. The only third-party OSA language components were either really, really limited in capability, or didn't work quite right (e.g. Mark Aldritt's JavaScriptOSA or my own PyOSA, both of which are long-dead). Plus the Carbon Component Manager API was deprecated in 10.8, so any third-party OSA components are dead in the water nowadays anyway. (Apple have added a new 'JavaScript for Automation' OSA component in 10.10, but it's full of crippled features and application incompatibilities, so while it might do for light use with some apps I would not touch it for serious production work either.)


    Getting back to Python editors... As others have noted, the OP's screenshot is basically fake: you can write Python code in any text editor (even Script Editor), but you won't get syntax highlighting or be able to run it unless you use an editor that has those features built in. Even if you did have a working Python OSA component, SE's a miserably poor tool. Personally, I use TextWrangler - it's basic but free (I recommend customizing the preferences to bind the Run menu item to Cmd-R). There's plenty other options if that's not to your taste - the Python wiki includes a list of editors which may be a useful starting point.
     
  7. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
  8. afro-ninja macrumors member

    Joined:
    Jan 27, 2013
    #8
    I use Eclipse with the add-on PyDev. It's a bit of hassle to set up (you must manually install Java JDK 7 first, and install the right Eclipse from the different options otherwise it won't work...), but it's exactly what you're looking for. Color coding, runs within the editor etc :)
     
  9. mw360 macrumors 65816

    mw360

    Joined:
    Aug 15, 2010
    #9
    I use Komodo Edit. It's free. No tricky set-up. Python just works (for me anyway). Syntax colouring and checking, loads of other handy stuff. Press cmd-R to run your script inside the editor.
     
  10. Freez macrumors newbie

    Joined:
    Feb 9, 2011
    #10
    BBEdit

    I use BBEdit. It seems to work well with python. BBEdit has saved me countless hours with regex in the find/replace. Also, it can select text in a document by the column.
     
  11. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #11
    Even TextEdit can do rectangular selection. Simply hold down the OPTION key, then click and drag. The selection will expand/contract as a rectangular area, rather than by whole lines.

    If you also hold down the CMD key, you can then select discontiguous rectangular areas.
     
  12. Freez macrumors newbie

    Joined:
    Feb 9, 2011
  13. VideoBeagle thread starter macrumors 6502a

    Joined:
    Aug 17, 2010
    Location:
    App Q&A testing by request.
    #13
    Woah..something new learned!

    Thanks for all the editor recomendations!
     
  14. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #14
    No. Eclipse is a bloated piece of garbage. It doesn't handle Java (the language it was made for) well and it handles everything else worse.

    I find that just going with a text editor that can offer autocompletion and text highlighting (like sublime) + a console is best for most Python projects. If you need to do stuff like remote debugging (IE, if you're using Django) you may want to use a good IDE, such as PyCharm.

    Never settle for the crap that is Eclipse.
     

Share This Page