Skip navigation
Currently Being Moderated

Lion & osascript

Jul 23, 2012 2:15 PM

Tags: #lion #mac #security #permission #osascript

I have several plugins that use on-the-fly generation of text scripts expected to be executed by osascript interpreter.

 

That worked fine up through Snow Leopard, but Lion usually disallows such stuff.

 

Any ideas for work-around?

 

Rob

 
Replies
  • Currently Being Moderated
    Jul 23, 2012 3:54 PM   in reply to Rob Cole

    Nothing specific, sorry. Is there a way that you could write a static script that gets authorised somehow, and have it read configuration from a file instead? Or maybe its the location being written to (/tmp ?) that doesn't support execution of scripts?

     

    But when testing ideas for a work around I'd suggest making sure it can work in a sandboxed environment. Now that there is a Mac App Store version of Lightroom I suspect it will only be a matter of time before Apple force them to have it run in sandboxed mode.

     

    Matt

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 23, 2012 5:06 PM   in reply to Rob Cole

    Rob Cole wrote:

     

    How does one "make sure it works in a sandboxed environment"?

     

    I'd suggest reading up about Mac's sandbox and temporary exception entitlements.

     

    I haven't seen anyone say that the Mac App Store version of Lightroom will become sandboxed but I can't see how they will be able to avoid it. If you are going to be reworking this part of your code anyway it wouldn't hurt to think ahead.

     

    Matt

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2012 5:38 AM   in reply to Matt Dawson

    So, the Mac App Store version can't launch any external scripts?  Can anyone confirm that?  Can I somehow emulate the App Store version's sandboxing features with sandbox-exec?

     

    I have a plugin that does keyboard stuffing (http://www.capturemonkey.com/excessor), it's working fine on Lion and Mountain Lion, but I only have regular downloadable version of Lightroom.  I'm not too eager to purchase another copy just for testing...

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2012 1:49 PM   in reply to Rob Cole

    Yes, Excessor uses osascript to stuff in keyboard events.

     

    If it helps, I can try out your plugin, just tell me what to install and how it is supposed to work

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2012 4:59 PM   in reply to jarnoh

    To be clear, I am certain that the Lightroom 4.1 MAS version is not

    sandboxed. So the problems you are experiencing are likely to do with the

    operating system upgrade only.

     

    I was advising Rob that if he changes code he should future proof it to

    work in a sandboxed environment. I suspect that a future version will be

    forced by Apple to introduce sandboxing so might as well get ahead of the

    curve while making any change.

     

    I am not aware of any way to simulate a sandboxed MAS version without

    having purchased the MAS version first. Sorry.

     

    Matt

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2012 8:19 PM   in reply to Rob Cole

    I don't have much experience with Mac, and none with Lion, so can't give

    you any definitive answers.

     

    It is possible Lion has introduced some additional security around the

    functionality you are relying upon and that is causing the issues you are

    seeing. It might be the MAS version that is hitting the issue but is a Lion

    triggered issue and not an LR sandboxing one. Pretty sure I read somewhere

    there were malware related features in Lion. I wouldn't be surprised if key

    press stuffing and dynamic scripts were viewed with suspicion by such a

    feature.

     

    Matt

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 5:10 AM   in reply to Rob Cole

    Rob, are you seeing this behaviour yourself, or has one of your users reported it?  Are you getting multiple reports or just single incident?

     

    I haven't heard of any problems with Lion keyboard shortcuts with my plugins, but there isn't that many users with OS X 10.7.

     

    I find it hard to believe that there would be issues with dynamic scripts, maybe there's a hidden switch to adjust System Events permissions somewhere (and someone has non-default configuration...)

     

    BTW. My plugin skips the Lightroom activate part, since its invoked from menu, I'm expecting Lightroom to be already active

     

    Jarno

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 1:25 PM   in reply to Rob Cole

    Here's the logfile

     

    2012-07-30 20:09:26 +0000, INFOLocking one photo
    2012-07-30 20:09:26 +0000, INFO1 photo photos under consideration for snapshot and/or mark...
    2012-07-30 20:09:26 +0000, DEBUGMain style: RC Finished, Summarized
    2012-07-30 20:09:26 +0000, DEBUGSnapshotted /Volumes/dada/Pictures/2012/2012-07/2012-07-15/_7150537.ORF with Master 2012-07-30 23:09:26 Locked (test)
    2012-07-30 20:09:26 +0000, DEBUGLens profile corrections are defined, but disabled.
    2012-07-30 20:09:26 +0000, DEBUGMarked edit history of /Volumes/dada/Pictures/2012/2012-07/2012-07-15/_7150537.ORF with details: no adjustments
    2012-07-30 20:09:26 +0000, DEBUGMarked edit history of /Volumes/dada/Pictures/2012/2012-07/2012-07-15/_7150537.ORF with profile: Adobe Standard
    2012-07-30 20:09:26 +0000, DEBUGMarked edit history of /Volumes/dada/Pictures/2012/2012-07/2012-07-15/_7150537.ORF with snap: Master 2012-07-30 23:09:26 Locked (test)
    2012-07-30 20:09:26 +0000, DEBUGsnapshotted and/or marked /Volumes/dada/Pictures/2012/2012-07/2012-07-15/_7150537.ORF
    2012-07-30 20:09:26 +0000, ERROR****** ERROR #2: Unable to lock /Volumes/dada/Pictures/2012/2012-07/2012-07-15/_7150537.ORF because Non-zero exit code returned by command: "chmod" a+w "/Volumes/dada/Pictures/2012/2012-07/2012-07-15/_7150537.xmp", exit-code: 256
    2012-07-30 20:09:26 +0000, INFOFinalizing to lockage of 0 photos...
    2012-07-30 20:09:26 +0000, DEBUGPrevious lib filter table restored.
    2012-07-30 20:09:26 +0000, DEBUGPrevious lib filter table restored.
    2012-07-30 20:09:26 +0000, DEBUGBackground state changed to: running
    2012-07-30 20:09:26 +0000, INFO0 photos locked.

     

     

     

    I'm not seeing any mention of osascript, and the chmod probably fails because the XMP is not generated. 

     

    From commandline, osascript code mentioned before works fine (I'm seeing the warning dialog, because I clicked reset-all-warnings buttons just to be sure)

     

    I'm guessing its problem with your code, but i didn't understand the stuff enough to add more logging :-)

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 1:31 PM   in reply to jarnoh

    I rerun it, but first saved XMP file myself (Cmd+S).  Now it works   So the problem is not the osascript, but chmod

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2012 10:56 PM   in reply to Rob Cole

    Still, I'm not buying this as a wide spread problem.  It's definately not a SDK problem anyway.

     

    Perhaps the users system is just misconfigured, or could use the magic of Disk Utility's repair permissions.  Error code 256 indicates a file access error, perhaps they have wrong permissions under /System/Library/CoreServices/System Events.app or something...

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2013 9:31 PM   in reply to Rob Cole

    Yes, assistive devices option might be required for some operations, but I think I'm actually not using it in Excessor.

     

    Additionally, you can also enable it from osascript, this will trigger a password dialog if it is not already set:

     

    osascript -e 'tell application "System Events" to set UI elements enabled to true'

     

    As a side note, I think the UI dialog option will be moved to different place in OS X 10.9.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2013 8:12 AM   in reply to Rob Cole

    Keyboard events work for me even without this option set on, but e.g. reading window controls fails with error message.  I don't know if that is the case always, but I've had less need for user support on Mac than on Windows (I used JScript for event stuffing and it's a mess with 64bit Windows because many installers corrupt its registration).

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2013 9:44 AM   in reply to Rob Cole

    To create virtual copy on OSX, I just execute:

     

    osascript -e 'tell application "System Events"' -e "keystroke \"'\" using {command down}" -e 'end tell'

     

    I don't have to worry about activating window, because it is invoked from UI button.  Why this doesn't require assitive device permission is beyond my knowledge.

     

    On Windows, I wrote my own keyboard event stuffer in Win32 C++, it actually less lines than your AHK code

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 18, 2013 1:28 AM   in reply to Rob Cole

    Actually, I can also activate window without having assitive devices enabled, so that is not the real reason. 

     

    Sending key events to active window can of course fail with popup windows, but it is extremely unlikely, and it can also happen between AHK's activate and sendkeys methods.  It is much more likely that there is some other LR related problem, like running out of diskspace

     

    In case I don't get expected amount of virtual copies, I'm notifying the user.  Just wishing the LR5 undocumented method would work for all cases...

     

    And yes, Windows version just sends the keystrokes, I was just saying that it is not that much of code, no matter what tools you use.  I just prefer simpler techniques without additional dependencies, it is typically easier to debug them.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points