![]() This function uses shell commands to modify the application’s ist. See try set application_path to ( path to application theApplication ) set bundle_identifier to get bundle identifier of ( info for the application_path ) tell application "Finder" set the application_to_modify to ( application file id bundle_identifier ) as alias end tell set the app_path to ( POSIX path of the application_to_modify ) set the app_info_path to (( POSIX path of the application_to_modify ) & "Contents/Info" ) set the plist_filepath to the quoted form of the app_info_path - determine which Mac OS X version currently running set osver to system version of ( system info ) - Make a backup of the Application bundle and overwrite the plist file do shell script "ditto -c -k -sequesterRsrc -keepParent " & app_path & space & app_path & ".quit-open.zip" with administrator privileges do shell script "defaults write " & app_info_path & space & "NSAppleScriptEnabled -bool YES" with administrator privileges do shell script "chmod a+r" & space & app_info_path & ".plist" with administrator privileges if osver >= "10.7" then if osver >= "10.8" then - Assume Xcode is installed do shell script "sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/codesign_allocate /usr/bin" with administrator privileges end if do shell script "codesign -f -s - " & app_path with administrator privileges end if on error message number errorNumber - Something went wrong if message is not equal to "ln: /usr/bin/codesign_allocate: File exists" then display dialog "Problem with enabling AppleScript for " & theApplication & ": " & message & " - Error number: " & errorNumber end if end try end enableAppleScripting ![]() On enableAppleScripting ( theApplication ) - Add AppleScript support to an application by overwriting the ist in - the Application bundle. ![]() This is useless, and I want that window to be hidden when it is opened. When Flexiglass is opened, it shows the preferences window/pane. The actions to perform when the trigger applications is terminated are slightly more complicated. If so, it traverses the list of applications to open, and to quit. Here you see I make use of a list of pTriggerLaunchApplications to check if the launched application should trigger actions. On appLaunchNotification_ ( notification ) set theLauchedApplication to ( notification's userInfo's NSWorkspaceApplicationKey's localizedName ()) as text if theLauchedApplication is in pTriggerLaunchApplications then - Open the associated applications repeat with applicationToOpen in pOpenOnLaunchApplications tell application applicationToOpen to activate end repeat - Close the associated applications repeat with applicationtoClose in pCloseOnLaunchApplication tell application applicationtoClose to quit end repeat end if end appLaunchNotification_ This enables us to register for launching and termination of applications, using the shared instance of the NSWorkspace class: It shows that AppleScript (which is a pretty funny language) is able to work with the Cocoa framework. Clearly this are needless steps for any programmer, so I searched a bit for this problem and found a helpful starting point in the following StackOverflow question: Close App A when App B closes: Mac OS X 10.7.3. So when opening Matlab, first I would need to close Flexiglass. For me this was Flexiglass, and it produced an Java error in Matlab on almost any GUI action (Although is seems that this only occurs in a multi-monitor setup). When the checkbox in System Preferences > Accessibility > Enable access for assistive devices is checked, there is somewhere on your system an application that requires it. Second, there is a strange and irritating problem with Matlab and applications that use the Mac OS X support for assistive devices, such as (in my case) Flexiglass. After using Matlab there is no need for the connection, so every time I am done with it, I have to terminate the VPN-client. Only then the Matlab application can load successfully. First, my license of Matlab requires me to setup a VPN-connection to my university. I had two applications which needed to be opened and closed. The task to automate was my Matlab-workflow. I will show my approach and problems I found. Thanks to AppleScript this is an “easy” task. The steps are fast to perform, but still… it just feels… wrong. Every now and then you find yourself doing a repetitive tasks consisting of a few small steps.
0 Comments
Leave a Reply. |