Wednesday, May 23, 2018

#1 2018-04-20 10:48:39 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

stopping script from asking for assistive access

Hi all,

I'm writing an installer for a set of java scripts I co-developed with colleagues of mine, and am running into a frustrating issue that's slightly hard to explain.

The main installer apple script is installing a number of things, including another application that needs to run when the installer finishes. For reference, I'll call that app Numpad. The numpad, not the installer itself, requires assistive access be granted in the accessibility pain of system preferences to work properly. That's fine, and is what I expect. However, since I've integrated the installation of this app into the main installer, the installer now also wants assistive access, which is likely because I'm checking if the numpad is running, to basically see if assistive access has been successfully granted or not.  the process of checking this seems to cause the main installer to ask for assistive access, which I don't want. Is there another way of accomplishing this, or a way to suppress the script from putting itself in the list for assistive access? It doesn't seem to actually need it, because if you don't allow access it still finishes successfully. Thoughts? Full script is below for reference. Sorry, it's long sad



Applescript:


tell application "System Events"
   if (name of processes) does not contain "VoiceOver" then
       display alert "Please enable VoiceOver to continue installing FloTools." buttons {"OK"} default button "OK" giving up after 3
       tell me to quit
   end if
end tell
try
   tell application "VoiceOver"
       output ""
   end tell
on error
   display alert "Error!" message "This installer requires VoiceOver to be controled with AppleScript. To enable this, please go to the general tab of VoiceOver utility, and check the checkbox labeled 'Allow VoiceOver to be controld with AppleScript.' Then restart the installer." as critical buttons {"Quit", "Open VoiceOver Utility"} default button "Open VoiceOver Utility"
   set {buttonReturned} to {button returned of result}
   if buttonReturned is "Quit" then
       tell me to quit
   else if buttonReturned is "open VoiceOver Utility" then
       tell application "VoiceOver Utility" to activate
       tell me to quit
   end if
end try
set floTools to (path to me as text) & "Contents:Resources:Flo Tools.kmmacros"
set views to (path to me as text) & "Contents:Resources:Flo Tools:Plug-In Views"
set source to views
set destination to (path to library folder from user domain as text) & "Application Support"
set macroSource to (path to library folder from user domain as text) & "Application Support" & ":Keyboard Maestro" & ":Keyboard Maestro Macros.plist"
set floPad to (path to me as text) & "Contents:Resources:Flo Tools:FloNumPad.app"
set appDestination to (path to applications folder as text)
set flotoolsTemplate to (path to me as text) & "Contents:Resources:Flo Tools:Flo Tools Session Template.ptxt"
set sessionTemplates to (path to home folder as text) & "Documents:Pro Tools:Session Templates"
try
   tell application "Finder" to get application file id "com.stairways.keyboardmaestro.editor"
   set doesExist to true
on error
   set doesExist to false
   display alert "Keyboard Maestro Not Found!" message "FloTools was unable to find the application Keyboard Maestro, which is required for FloTools to function. Please install Keyboard Maestro, and restart the FloTools Installer." as critical buttons {"OK"} default button "OK"
   return
end try

display dialog "To continue with the installation of FloTools, click next." buttons {"Cancel", "Next"} default button "Next" cancel button "Cancel" with title "Welcome to the FloTools Installer."
display dialog "
Flo Tools is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your discretion) any later version.
Flo Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, expressed or implied, of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
http://www.gnu.org/licenses/

Flo Tools collects macro usage data in order to improve the user experience. No personal information or information that could identify an individual user will be collected."
buttons {"Quit", "Agree"} default button "Agree" with title "License Agreement"
set {buttonReturned} to {button returned of result}
if buttonReturned is "Quit" then
   tell me to quit
end if
try
   delay 1
   tell application "VoiceOver" to output "Please wait while Flo Tools is being installed."
   delay 1.5
end try
set progress total steps to 4
set progress completed steps to 1
set progress description to "Installing FloTools."
set progress additional description to "Please wait while Flo Tools is being installed."
delay 1
set progress completed steps to 2
set progress additional description to "Installing files."
tell application "VoiceOver" to output "Installing files."
delay 1
tell application "System Events"
   set checkFolder to (destination & ":Flo Tools" as text)
   if not (exists folder checkFolder) then
       tell application "Finder"
           set folderName to "Flo Tools"
           make new folder at folder destination with properties {name:folderName}
       end tell
   end if
end tell
tell application "Finder"
   set checkBackup to (destination & ":Flo Tools" & ":Backups" as text)
   if not (exists folder checkBackup) then
       set folderName to "Backups"
       make new folder at folder checkFolder with properties {name:folderName}
   end if
end tell
tell application "System Events"
   set checkViews to (destination & ":Flo Tools" & ":Plug-In Views" as text)
   if not (exists folder checkViews) then
       tell application "Finder"
           duplicate folder views to folder checkFolder
       end tell
       tell me to activate
   else
       tell me to display alert "FloTools Plug-In Views already exist." message "FloTools has detected that you already have Plug-In Views installed. Flo Tools will now make a backup of your Plug-In Views, and store them in the Flo Tools directory of Application Support. The folder will then be merged with updated Plug-In Views from the installer. To restore user-created Plug-In Views, please copy the necessary text files from the backup." as informational buttons {"Next"} default button "Next"
       tell application "Finder"
           set timeStamp to do shell script "(date '+%m-%d-%Y, %I %M %S %p')"
           set folderName to "Backup" & space & timeStamp
           set BackupSource to (checkFolder & ":Plug-In Views" as text)
           set backupFolder to make new folder at folder checkBackup with properties {name:folderName}
           duplicate folder BackupSource to backupFolder
           duplicate file macroSource to backupFolder
           try
               merge(views, checkViews)
           end try
       end tell
   end if
   if not (exists folder sessionTemplates) then
       display alert "FloTools was unable to find your session templates folder. The default location for this folder is in your home directory, under Documents/Pro Tools. Please locate this folder on the next screen." buttons {"Next"} default button "Next"
       tell application "Finder"
           set sessionTemplatesUser to choose folder with prompt "Where is your default Pro Tools documentation and settings folder?"
           set checkTemplates to (sessionTemplatesUser & ":Flo Tools" as text)
           if not (exists folder checkTemplates) then
               set folderName to "Flo Tools"
               set tempDestination to make new folder at folder sessionTemplatesUser with properties {name:folderName}
           end if
           duplicate file flotoolsTemplate to tempDestination with replacing
       end tell
       tell me to activate
   else
       tell application "Finder"
           set checkFloTemplates to (sessionTemplates & ":Flo Tools" as text)
           if not (exists folder checkFloTemplates) then
               set folderName to "Flo Tools"
               set floTempDestination to make new folder at folder sessionTemplates with properties {name:folderName}
               duplicate file flotoolsTemplate to floTempDestination with replacing
           else
               duplicate file flotoolsTemplate to (sessionTemplates & ":Flo Tools" as text) with replacing
           end if
       end tell
   end if
end tell

tell me to activate
delay 3
set progress additional description to "Updating macros."
set progress completed steps to 3
tell application "VoiceOver" to output "Updating macros."

if doesExist is true then
   set installMacros to (path to me as text) & "Contents:Resources:Scripts:install macros.scpt"
   run script file installMacros
end if
delay 1
set checkNumPad to (appDestination & "FloNumPad" as text)
tell application "Finder"
   if not (exists file checkNumPad) then
       tell me to activate
       delay 2
       tell me to display alert "Install FloNumPad?" message "Flo Tools comes with an additional component, called FloNumPad, which allows a standard qwerty keyboard to simulate a numpad by pressing the function key with specific letters. It is recommended that you install FloNumPad and FloTools together, but it is not required. Would you like to install FloNumPad now?" as informational buttons {"No thanks, I'll install it later.", "Yes, install now!"} default button "Yes, install now!"
       set {buttonReturned} to {button returned of result}
       if buttonReturned is "Yes, install now!" then
           tell application "Finder"
               duplicate file floPad to appDestination with replacing
           end tell
           tell me to display alert "FloNumPad has been successfully installed. However, assistive access is required for FloNumPad to function properly. Upon pressing thenext button, a system window will appear asking you to grant access to FloNumPad. Please go to System Preferences to do this, and then return to the FloTools Installer to continue." buttons {"Next"} default button "Next"
           tell application "FloNumPad" to run
           delay 1
           tell process "universalAccessAuthWarn"
               activate
               set frontmost to true
           end tell
           tell me to display dialog "When you've successfully granted FloNumPad assistive access, click next to continue." buttons {"Next"} default button "Next" with title "Waiting for Assistive Access Permission"
           delay 1
           repeat until (exists process "FloNumPad")
               delay 1
               tell application "FloNumPad" to run
               delay 1
               tell application "System Events"
                   if not (exists process "FloNumPad") then
                       tell me to display alert "Error!" message "Flo NumPad has still not been given accessibility access. Please try checking the box again in System Preferences and press next when you're ready to continue." as critical buttons {"Cancel", "Next"} default button "Next" cancel button "Cancel"
                       delay 1
                       tell process "universalAccessAuthWarn"
                           activate
                           set frontmost to true
                       end tell
                   end if
               end tell
           end repeat
       end if
   else
       if process "FloNumPad" exists then tell application "FloNumPad" to quit
       tell application "Finder"
           duplicate file floPad to appDestination with replacing
       end tell
       delay 1
       tell application "FloNumPad" to run
   end if
end tell
set progress completed steps to 4
tell me to activate

tell application "VoiceOver" to output "Installation complete."
delay 1
display dialog "FloTools has been successfully installed." buttons {"Done"} default button "Done" with title "Installation successful."

Last edited by rfscripter (2018-05-17 04:14:59 pm)


Filed under: Installer, accessibility

Offline

 

#2 2018-05-17 04:20:35 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

Re: stopping script from asking for assistive access

I posted this message a little while ago, but have now edited it to reflect changes. I originally couldn't figure out why the end of the main installer wanted assistive access in the first place, but realized what it was and added to the original post. smile Thanks in advance for any help, it is greatly appreciated.

Offline

 

#3 Yesterday 02:47:14 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

Re: stopping script from asking for assistive access

I figured it out!! big_smile Posting here in case it helps someone out who may be having a similar problem. I was right, the assistive access prompt was coming from the repeat loop at the end of the script, where it checks the running processes for the one I'm looking for. However, if I change the statement from "if exists process 'processName' then..." to "if (name of processes) contains/does not contain 'processName' then..." the mac no longer prompts for access. To me, both statements mean the same thing, but I guess the computer desires more granular control over what you are allowed and not allowed to do without that access.
I actually looked at the beginning part of my script to figure this out; if you look at the first few lines, and then that last repeat loop the differences between the statements will make sense. Hopethis helps someone out there smile

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)