0
votes

Thanks for taking the time to read my question.

It's pretty simple, but i am a complete noobie to this, so am having some trouble.

Is it possible to have an applescript that will check the mac app store for updates, and if there are, output the number of updates to someplace?

A good example of this is (if you are aware of it) the geeklets that check for unread mail, and then outputs it to the desktop.

EDIT:
I downloaded a geeklet for the unread mail (as referenced above), and using that as a starting point, I tried to write my own script.

set run_bool to 1

tell application "System Events"
    set run_bool to count (every process whose name is "App Store")
end tell


if run_bool is 1 then

    tell application "App Store"

        set update_count to 0
        set output_string to ""

        repeat with upd in Apps in Updates
            if upd's download is not true then
                set update_count to update_count + 1
            end if
        end repeat

        if update_count is 0 then
            set output_string to "zero"

        else if update_count is 1 then
            set output_string to "one"

        else
            set output_string to "two"
        end if
    end tell

else
    set output_string to "not running"
end if

return output_string

now this is not my final code, but simply to check to see if it will work and what the output would be.

On compilation I get an error saying

error "The variable Updates is not defined." number -2753 from "Updates"

as well as

Syntax Error
Expected end of line but found unknown token

Also, when I stopped compilation, this appeared below the last line in my code

tell application "GeekTool Helper"
activate
«event ascrgsdf»

Any help is appreciated.

1
Any reason you don't just click the  menu? The number of updates is shown next to the "App Store..." menu item, assuming the "Automatically check for updates" option is checked in System Preferences' App Store tab.foo
@foo I am aware of this, and I also have app store on my dock, which shows the update count in the little red circle. However, I'm streamlining my desktop to be as minimal as possible. Having it automatically shown on my desktop via a geeklet will allow me to be notified every time there is an update to be done, and I don't have to periodically check the App Store manually.magg0t
Your script can't work because App Store.app is not actually AppleScriptable. It shows a dictionary in Script Editor, but that's only the default Cocoa Scripting terminology you see when the NSAppleScriptEnabled flag is set in the app's Info.plist file. It doesn't actually do anything useful unless the developers have provided their own app-specific terms and Objective-C code to wire it all up, which they haven't. (App Store's not the only Apple app to do this "Fake AppleScriptability" either, which is very annoying/confusing/insulting, but then most Apple devs want AS to DIAF anyway.)foo

1 Answers

0
votes

@foo is pretty right on with his idea. This code only requires one line. In the second line, I used display notification, but you substitute it with you preferred method to pass on the value.

tell application "System Events" to tell (first application process whose ¬
frontmost is true) to set returnValue to title of ((first menu item whose title ¬
begins with "App Store") of menu "Apple" of menu bar 1)
display notification returnValue

Result:

"App Store…, 1 update"

notification

menu bar items are accessible everywhere (e.g. windowed/numeral desktop mode, fullscreen mode, dock hidden/disabled).

Make sure accessibility is enabled for Script Editor, or whichever app you use to invoke the script, to gain access to the UI.

There is just one weird thing: if I had used begins with "App Store..." instead of begins with "App Store", the code would be a dud. I don't know why - it might has to do with escaped characters and the .... Anyone who knows please enlighten me with a comment.

As for your code, I can tell from AppleScript Dictionary that Updates is not a property of App Store.app. Nor is any other categories in the UI. To get to the Dictionary, open Script Editor and press CMD+SHIFT+O

In addition, if you want to use return statement, you need an explicit handler. In other words, you need to wrap the code between on run and end run.