5 Replies
      Latest reply on Jan 30, 2019 2:15 PM by john daniel
      parker9 Level 1 Level 1 (0 points)

        There is no way to script the Finder from a sandboxed app is there?

         

        Finder has no access-groups vai sdef, so the only way i could get this to work is by using

         

          <key>com.apple.security.temporary-exception.apple-events</key>

          <string>com.apple.finder</string>

         

        in the entitlements. Of course, this caused a rejection from Apple. Apparently, if i can convince the user to install AppleScript file(s) into FileManager.SearchPathDirectory.applicationScriptsDirectory it may work. Seems to be an high hurdle. Any other possible ways?

         

        I understand, it's a valid security concern. I'm only using AppleScript to get the Desktop icon names and positions, the Desktop View Options text size and icon size and the bounds of the Desktop window. I use the return data to 'memorize' and 'restore' various icon arrangements on the Desktop. Is there any other way to achieve this in an macOS app that would not be rejected? I expect not, since it appears only the Finder knows such information.

         

        Thanks,

        • Re: AppleScript and Finder in a sandboxed app
          john daniel Level 3 Level 3 (320 points)

          Generally, any apps that interact with other apps or the system are frowned upon. The process is designed to reject such apps. If you manage to get it working, you may regret it later. Any potential solution would require some kind of system hack or reverse engineering. Apple is pretty good about letting little things slide. But technically speaking, if it isn't an API listed in Xcode's documentation, then it is not allowed and cause for rejection.

           

          You yould probably have to reverse-engineer DS_Store files and try to extract the information from there. I'm not 100% certain the information is there. But even reading that file would require user consent, which you can't directly ask for in the Mac App Store. You can offer and document it, but you can't facilitate. You can allow the horse to drink, but you can't lead her there. And your app would have to be meaningfully functional without this access entirely.

            • Re: AppleScript and Finder in a sandboxed app
              parker9 Level 1 Level 1 (0 points)

              Thanks John.

               

              Since .DS_Store has never been documented, i'm not going to go down that rabbit hole. Again. If i recall correctly, icon positions are stored in .DS_Store only if the user manually moves the icons and further the Finder isn't required to follow the information in .DS_Store anyway.

               

              I did try to appeal the rejection pointing out the information from/to the Finder is all user generated and i never touch it other than to store it and retieve it at user request. They said, probably correctly, "no".

               

              They did say this, though:

              Finder access may be possible by having user select the location via OpenPanel.

               

              Please also be aware the app requires to install AppleScripts under Application Scripts directory in order to perform core functionality violates our “2.4.5 App installs Code” guideline.

               

              Perhaps i can play around w/ NSOpenPanel and get the user to select it.

               

              Not vey elegant or mac-like. Alas.

                • Re: AppleScript and Finder in a sandboxed app
                  john daniel Level 3 Level 3 (320 points)

                  Generally, the advice I give to people in these situations is this: Imagine how you would implement an iOS version of your app. Do that on the Mac. If that would be a paradox or impossibility, then pick a new project. The Mac, as we know it, is simply not long for this world.

                    • Re: AppleScript and Finder in a sandboxed app
                      parker9 Level 1 Level 1 (0 points)

                      That seems to be reasonable advice.

                       

                      I was able to figure out how to install the AppleScript via NSOpenPanel (trying to make it 'obvious' to the user why they need to hit the 'open' button...). Now i just have to refactor the rest of the code. I have a sneaking suspicion that even though i'm following the guidlines, App Store Review won't like it since the app has no functionality unless the user does hit 'open'.

                       

                      Hope you're incorrect about the future of Mac. i do expect Automation on the Mac will continue to be more limited which, i think, is a true shame. If one is looking for hope, we now have Shortcuts on iOS which may imply the future of Mac Automation. Particularly if you do sdef on Finder.app, the only access-group is to Siri...

                        • Re: AppleScript and Finder in a sandboxed app
                          john daniel Level 3 Level 3 (320 points)

                          You can change the text on that button. You can also set the title on the dialog. However, if your app has no functionality without this, then it would be a waste of time. In my experience, Apple will reject any app that asks for an escape from the sandbox. You can offer one, but you can't lead the user to it. Just having a button immediately visible in the app is enough for a rejection.

                           

                          Typically Apple rolls last year's iOS features into this year's macOS. Shortcuts for macOS is a strong possibility. Automator and AppleScript will probably be deprecated and removed next year or the year after.