URL scheme Mac App Store Search - app-store

I want to open the Mac App Store with an URL scheme.
Before october I used the link below
macappstore://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?q=
Followed by a search term like things.
Any ideas how the new URL scheme looks like on OS X 10.9 Mavericks?

Looks like the URL has changed very slightly in 10.11. The new URL is as follows:
macappstores://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?mt=12&ign-mscache=1&q=...

The following, AppleScript-based solution is just a stopgap, but may suffice in certain situations; for instance, I want to perform command-line based App Store searches from Alfred 2, which supports AppleScripts.
The script works on OSX 10.8+ (tested up to 10.10, the most recent version as of this writing).
On 10.8, it uses the macappstore:// approach, while on 10.9+ it uses GUI scripting - via the accessibility API, not by sending keystrokes, so it should be fairly robust.
Thus, on 10.9+, access for assistive devices must initially be enabled specifically for the application executing the script, which requires administrative privileges and - by OS design - several manual steps (which the script attempts to facilitate).
To try the script, paste it into AppleScript Editor, place a sample invocation at the top - e.g. my searchAppStore("dash"), then run it.
# Performs an App Store search via the App Store.app.
# Example:
# my searchAppStore("dash")
# Works on OS X 10.8+:
# - 10.8: Uses the macappstore:// URL scheme.
# - 10.9+: Sadly, GUI scripting (i.e., simulated user input) must be used,
# which requires that access for assistive devices be enabled as *one-time setup*
# for the application in whose context this script runs.
# While this script attempts to facilitate enabling this feature,
# user intervention is - by OS design - required.
on searchAppStore(searchTerm)
if my isPreMavericks() then # assumes: OS X 10.8
# We can use the macappstore:// URL scheme to submit a search.
tell application "System Events" to open location "macappstore://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?q=" & searchTerm
return
else # OS X 10.9+: alas, we must use GUI scripting.
# First, ensure that access for assistive devices is enabled -
# otherwise, GUI scripting won't work.
my ensureAssistiveAccess()
# Activate (and launch, if necessary) the App Store app.
tell application "App Store" to activate
# Use GUI scripting to simulate an interactive search.
tell application "System Events"
tell application process "App Store"
# !! CAVEAT: The spelling of the toolbar UI element changed from 'tool bar' (10.8)
# !! to 'toolbar' (10.9) - if you compile this script on 10.9, you'll end
# !! up with 'toolbar', which will break when PASTED into a 10.8 AppleScript
# !! window. If you're on 10.8 and get an error, change 'toolbar' to 'tool bar'.
set searchTextField to get text field 1 of group 7 of tool bar 1 of front window
set searchSubmitButton to get button 1 of searchTextField
set ok to false
repeat with i from 1 to 20 # Timeout is iteration count * delay period below.
set value of attribute "AXValue" of searchTextField to searchTerm
# !! Sadly, when App Store.app was just launched by this script, attempts to
# !! assign to the search field initially fail silently, until some time
# !! after startup. We simply keep trying for a while until we succeed.
if (value of attribute "AXValue" of searchTextField) = searchTerm then
# Click button to submit search.
# [If you run this on 10.8]
# !! On OS X 10.8, if this script just launched App Store.app,
# !! `tell application "App Store" to activate` didn't actually
# !! *activate* the app (it just launched it).
# !! Hence, we simply activate again here - BEFORE we
# !! submit the search - otherwise, it may not work.
tell application "App Store" to activate
click searchSubmitButton
# We're done.
return
end if
delay 0.3
end repeat
# Getting here means that submitting did not succeed within the timeout period.
# Raise an error.
error "Failed to submit search search term to the App Store application."
end tell
end tell
end if
end searchAppStore
# Tries to ensure that access for assistive devices is turned on so as to enable GUI scripting.
# - Up to 10.8.x, access can be turned on programmatically, on demand - via an admin authorization prompt.
# - From 10.9, the best we can do is display a GUI prompt, then open System Preferences to the relevant pane, then exit, telling the user to try again after interactively enabling access.
# Returns:
# Only returns if access is already enabled; throws an error otherwise.
# Example:
# my ensureAssistiveAccess() # throws error, if not enabled and couldn't be enabled programmatically (10.9+)
# # Alternatively, catch the error:
# try
# my ensureAssistiveAccess()
# on error
# # Exit quietly, relying on the prompt to have provided sufficient information.
# return
# end try
on ensureAssistiveAccess()
local ok, isPreMavericks, verOs, verMajor, verMinor, btn
# Determine if access is currently enabled.
tell application "System Events" to set ok to UI elements enabled
if not ok then
# See if we're running 10.8 or below
set {orgTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"."}}
set verOs to system version of (system info)
set verMajor to first text item of verOs as number
set verMinor to second text item of verOs as number
set AppleScript's text item delimiters to orgTIDs
set isPreMavericks to verMajor ≤ 10 and verMinor < 9
if isPreMavericks then # 10.8-: we can try to turn it on ourselves, which will prompt for authorization
try
# Try to turn it on - will prompt for authorization via admin credentials.
tell application "System Events"
set UI elements enabled to true
set ok to UI elements enabled # Check if the user actually provided the authorization.
end tell
end try
else # 10.9+: we cannot turn it on ourselves, it has to be enabled *interactively*, *per application*.
# Try a dummy GUI scripting operation - which we know will fail - in the hope that this will
# get the app at hand registered in System Preferences > Security & Privacy > Privacy > Accessibility.
# ?? Does this work?
try
tell application "System Events" to windows of process "SystemUIServer"
end try
set appName to name of current application
if appName = "osascript" then set appName to "Terminal" # ?? how can we deal with other apps that invoke `osascript`, such as Alfred?
set errMsg to "You must turn on ACCESS FOR ASSISTIVE DEVICES for application '" & appName & "' (System Preferences > Security & Privacy > Privacy > Accessibility) first, then retry."
try
display dialog errMsg & linefeed & linefeed & "Press OK to open System Preferences now; unlock, if necessary, then locate the application in the list and check it." with icon caution
# We only get here if the user didn't cancel.
# Open System Preferences and show the appropriate pane. (This is the best we can do in guiding the user - further guidance would require the very kind of assistive access we're trying to turn on.)
tell application "System Preferences"
activate
tell pane id "com.apple.preference.security"
reveal anchor "Privacy_Assistive"
end tell
end tell
end try
# We must return false, as we can't easily and reliably wait for the user to finish the operation.
end if
end if
if not ok then
if isPreMavericks then # This indicates that the authorization prompt was aborted; for 10.9+, errMsg was set above.
set errMsg to "You must turn on ACCESS FOR ASSISTIVE DEVICES first, via System Preferences > Accessibility > Enable access for assistive devices"
end if
error errMsg
else
return true
end if
end ensureAssistiveAccess
# Indicates if the OS version predates Mavericks (10.9).
# Example: my isPreMavericks() # -> true on 10.8.x and below
on isPreMavericks()
local verOs, verMajor, verMinor
set {orgTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"."}}
set verOs to system version of (system info)
set verMajor to first text item of verOs as number
set verMinor to second text item of verOs as number
set AppleScript's text item delimiters to orgTIDs
return verMajor ≤ 10 and verMinor < 9
end isPreMavericks

Simply add a "&mt=12" to existing iTunes Store Links.
This redirects queries to the Mac AppStore App instead of itunes.
Example for a search query in the MAS:
https://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?q=equinux&mt=12

Related

Automating editing SystemVersion.plist

I am currently using OSX10.10 and need to use MATLAB; however because they haven't updated the application to support 10.10 it will crash on launch.
Up until now I have been using pico to edit the SystemVersion.plist [1] (changing the version from 10.10 to 10.9); and that works great except that it is really annoying to edit the file every time I need to open MATLAB and re-edit it every time I close MATLAB.
What I want to do is when I start the script it will edit the SystemVersion.plist to the correct version so that I can run MATLAB without it crashing; and then when MATLAB exits it resets the version back from 10.9 to 10.10). I have a bit of code (which may be poorly written; I have never used applescript before);
tell application "System Events"
set ProcessList to name of every process
if "MATLAB" is in ProcessList then
tell application "System Events"
tell property list file "/System/Library/CoreServices/SystemVersion.plist"
tell contents
set value of property list item "ProductUserVisibleVersion" to "10.9"
set value of property list item "ProductVersion" to "10.9"
end tell
end tell
end tell
else
tell application "System Events"
tell property list file "/System/Library/CoreServices/SystemVersion.plist"
tell contents
set value of property list item "ProductUserVisibleVersion" to "10.10"
set value of property list item "ProductVersion" to "10.10"
end tell
end tell
end tell
end if
end tell
[1] - Error trying to installing JDK8 U11 OSX 10.10 Yosemite
I had the same approach, but came down to this solution: (for os x yosemite and matlab r2014a)
tell application "System Events"
set plistFile to property list file "/System/Library/CoreServices/SystemVersion.plist"
tell plistFile
get property list item "ProductVersion"
set value of property list item "ProductVersion" to "10.90"
end tell
end tell
do shell script "export MATLAB_USE_USERWORK=1" & ";/Applications/MATLAB_R2014a.app/bin/matlab -desktop &> /dev/null &"
display dialog "..." buttons {"Ok"} with icon note giving up after 10
tell application "System Events"
set plistFile to property list file "/System/Library/CoreServices/SystemVersion.plist"
tell plistFile
get property list item "ProductVersion"
set value of property list item "ProductVersion" to "10.10"
end tell
end tell
the dialog box is needed. delay (in seconds) does not do it for any reasons (i first used applescript to solve the matlab problem). there might be another solution, but this works for me.
if you are using a mac with retina display, you may want to install an java 7 runtime environment and replace the do shell script part with the following:
do shell script "export MATLAB_JAVA=\"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home\"" & "; export MATLAB_USE_USERWORK=1" & ";/Applications/MATLAB_R2014a.app/bin/matlab -desktop &> /dev/null &"
the icons still do look a little shitty, but the fonts aren't blurry anymore.
i hope this may help anybody facing the problem after updating to yosemite lately.
jens

Applescript: "set user interaction level to never interact" not working in illustrator

I'm trying to set it so that there's no user interaction when I open up my illustrator file using applescript, but the standard:
tell application id "com.adobe.Illustrator"
activate
set user interaction level to never interact
open theFile without dialogs
doesn't work for this plugin I have installed that checks for white overprints.
If it were up to me I'd just uninstall the plugin but it's for a work pc.
I also tried clicking the button automatically (with help from Tim Joe) by using:
try
tell application "System Events"
tell process "Finder"
click button "OK" of window "Adobe Illustrator"
end tell
end tell
end try
and I've tried
tell application "System Events"
tell process "Adobe Illustrator"
keystroke return
end tell
end tell
Does anyone know a way of solving this?
below is the full code as it currently stands:
set saveLocation to ((path to desktop) as string) --place to save the files
set theFile to choose file with prompt "Choose the Illustrator file to get outlines on"
set outputFolder to choose folder with prompt "Select the output folder"
tell application "Finder" to set fileName to name of theFile
set fullPath to (saveLocation & fileName) --file path of new .ai
set fileName to (text 1 thru ((length of fileName) - 3) of fileName) --remove .ai from fileName
set olPath to text 1 thru ((length of fullPath) - 3) of fullPath & "_OL.ai" --path of outlined file
tell application id "com.adobe.Illustrator"
activate
ignoring application responses
open theFile without dialogs
end ignoring
tell application "System Events"
tell process "Adobe Illustrator"
repeat 60 times -- wait up to 60 seconds for WOPD window to appear
try
tell window "White Overprint Detector"
keystroke return
exit repeat
end tell
on error
delay 1
end try
end repeat
end tell
end tell
save current document in file fullPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save file to desktop
convert to paths (every text frame of current document) --convert text to paths
save current document in file olPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save another copy to desktop with name + _OL.ai
end tell
tell application "Finder"
set newFolder to make new folder at saveLocation with properties {name:fileName}
move fullPath to newFolder --create new folder and move both new files into it
move olPath to newFolder
set newFolderPath to (newFolder) as string
set newFolderPath to text 1 thru -2 of newFolderPath --remove the trailing ":"
tell current application --zip up the new folder
set qpp to quoted form of POSIX path of newFolderPath
do shell script "cd $(dirname " & qpp & ")
zip -r \"$(basename " & qpp & ").zip\" \"$(basename " & qpp & ")\""
end tell
set zipFile to newFolderPath & ".zip"
move zipFile to outputFolder --move .zip to output
delete newFolder --delete folder on desktop left from zipping
end tell
--prepare a notification email
set presetText to "Hello,
Files Uploaded:
" & fileName & ".zip
To access our FTP Server:
http://217.207.130.162:8080/WebInterface/login.html
To access our FTP server, log onto our website below:
Username:
Password:
Thanks,
Joe"
tell application "Mail" --open up prepared email
activate
set theMEssage to make new outgoing message with properties {visible:true, subject:fileName, content:presetText}
end tell
--open file containing usernames and passwords for the FTP
do shell script "open /Users/produser/Desktop/FTP_Users"
I tracked down and installed White Overprint Detector I could see what you mean. I had to use an older version as I only have CS3, and I saw the dialog it produces when you open a document. The following worked for me to get it to dismiss:
tell application "Adobe Illustrator" to activate
tell application "System Events"
tell process "Adobe Illustrator"
repeat 60 times -- wait up to 60 seconds for WOPD window to appear
try
tell window "White Overprint Detector"
keystroke return
exit repeat
end tell
on error
delay 1
end try
end repeat
end tell
end tell
Since my original post seemed too objective to understand I will revise.
With in the tell block for illustrator look for your line that opens the file. Some commands allow with and without properties. Try applying the "without dialogs" property to look something like this.
tell application id "com.adobe.Illustrator"
open file (VariableOfFilePath) without dialogs
end tell
Update:
Two work arounds I can think of. 1) Try telling system events to tell AI to open without dialogs
tell application "system events"
tell application id "com.adobe.Illustrator"
open file (VariableOfFilePath) without dialogs
end tell
end tell
Other is just add in a bit that will just okay the prompt.
try
tell application "System Events"
tell process "Finder"
click button "Continue" of window "Adobe Illustrator"
end tell
end tell
end try
Can try just having it accept the default button.
tell application "System Events"
tell process "Finder"
keystroke return
end tell
end tell

Is there a conditional command in applescript that lets the user quit the app

Is there a conditional command in applescript that lets the user quit the app. I turned my applescript to an app using automator. However, the script is set to run constantly until its cycled through hundreds of scripts. Is there a conditional command statement that I can use that will end the application while its running?
property MyUserName : ""
if MyUserName is "" then
display dialog "User Name:" default answer "" buttons {"Cancel", "Continue…"} default button 2
copy the result as list to {button_pressed, text_returned}
set {returnedText, returnedButton} to the result as list ---> {"some text", "OK"}
if button_pressed is "Cancel" then
beep
return
end if
if text_returned is not "" then set MyUserName to text_returned
say "Hello," using "Karen"
say (returnedText) using "karen"
else
display dialog "Stored user name: " & MyUserName buttons {"Ok"} default button 1 with icon 1
end if
say "For your information, please start the Amuse App everytime you log on... and I will speak to you at random times during your visit with me." using "Karen"
delay 20
try
repeat 105 times
set pathToMyFolderOnDesktop to ("Macintosh HD:Users:jr:Desktop:") & "Dsource:" as alias
set rnd to (random number from 1 to 105)
set rndFileName to (rnd as text) & ".scpt"
set FullPath to pathToMyFolderOnDesktop & rndFileName as text
set myScript to load script (FullPath as alias)
run script myScript
end repeat
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
return
end try
You could do something like that:
display dialog "Shall I proceed?" buttons {"Quit", "Proceed"} default button 2 giving up after 10
if button returned of result is "Quit" then tell me to quit
It's using giving up after 10 which means that that the script proceeds after 10 seconds when the user does not press any button.
To quit it from outside isn't so easy when it's an automator app because they look all the same to the system so you can't really use the application name to tell it to quit. Maybe one could use the full path, like:
tell application "/Volumes/Applications/MyAutomatorApp.app" to quit
(you can drag your automator app into the script to paste in the full path)

Applescript: Close Word document? (Office 2011)

i'm simply trying to close a document (without quitting word), but this does not work.
I've tried :
close documents saving no
close active document
close document 1
but none of this is working..
The error I get (on the close line) is:
Microsoft Word got an error: The object you are trying to access does not exist
Here is a simplified script. Anyone have any ideas? All examples online seem to use this syntax, not sure if anything changed in the mac office 2011 version?
set input to {POSIX path of "/Users/Wesley/Desktop/test.doc"}
--ENABLE GUI SCRIPTING
tell application "System Events"
if UI elements enabled is false then set UI elements enabled to true
end tell
--RUN THE GUISCRIPT
set pdfSavePath to POSIX path of (choose folder with prompt "Set destination folder")
repeat with x in input
display dialog x
tell application "Microsoft Word"
activate
open x
set theActiveDoc to the active document
close theActiveDoc saving no
return
end tell
end repeat
close active document and close document 1 both work for me. Perhaps you need a delay statement before the theActiveDoc variable is assigned?

Simple script no longer works on Lion

I have a simple Applescript that takes a number of images in a folder that you select and then mirror images the images using Graphic Converter. This script will run if I place it in a new AS file; however, if I try to run it a second time I get the following error "Can't get window 1 of application "GraphicConverter". Invalid index."
This script always ran on OSX 10.6
I'm running OSX 10.7.4 and Graphic Converter 8.1 (latest version).
Here is the script
tell application "Finder"
activate
set loopFinish1 to 0
set pathName to (choose folder with prompt "Choose Folder Containing Images")
set fileList1 to every file of folder pathName
set loopFinish1 to count of items of fileList1
end tell
tell application "GraphicConverter"
activate
repeat with i from 1 to loopFinish1
set currentFile to item i of fileList1
open currentFile as alias
mirror window 1 in horizontal
close window 1 saving yes
end repeat
end tell
This is driving me crazy!
GraphicConverter has other windows (visible and invisible), it's preferable to use the document to get the right window.
Also, perhaps the image doesn't open, so no window, use a try block.
activate
set pathName to (choose folder with prompt "Choose Folder Containing Images")
tell application "Finder" to set fileList1 to (document files of folder pathName) as alias list
tell application "GraphicConverter"
activate
repeat with tFile in fileList1
set currentDoc to open tFile
set CurrWindow to (first window whose its document is currentDoc)
mirror CurrWindow in horizontal
close currentDoc saving yes
end repeat
end tell