• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Lookup Name from App-Page on MacUpdate.com in Downloads Folder with Spotlight
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lookup Name from App-Page on MacUpdate.com in Downloads Folder with Spotlight


  • Subject: Lookup Name from App-Page on MacUpdate.com in Downloads Folder with Spotlight
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 30 Mar 2017 05:55:01 -0500

Hey Folks,

I use MacUpdate to keep current with Mac apps and have been a member for many years now.

I don't especially like their MacUpdate Desktop app, so I don't use it very often.

That means I have to drive by every so often and eyeball the place.

I run through the list and Cmd-Click items to open them in background tabs in Safari.

Then I run through the tabs to see if there's anything I want to scope-out or download.

If I haven't been keeping up with installs I might have one or more old versions in my Downloads folder hierarchy.

I wrote this script, so I could hit a hotkey and immediately list any items in the Downloads folder.

That gives me a quick check to make certain I haven't downloaded the current version before (if I don't know) and lets me clean out old versions quickly before downloading the new one.

kMDItemFSName:<item-name> appears to work fine in Sierra, but I'm not certain it will in previous versions of macOS.

The script will open the Downloads folder if it's NOT frontmost in the Finder.

It will reuse the Search window if it is frontmost.

Scripting this makes it too easy not to do, whereas when it was a manual task I often blew it off.

Enjoy.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/03/30 12:02
# dMod: 2017/03/30 03:48 
# Appl: Safari, Finder, System Events
# Task: Lookup Name from App-Page on MacUpdate.com in Downloads Folder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Finder, @Safari, @System_Events, @Lookup, @Name, @App-Page, @MacUpdate.com, @Downloads, @Folder, @Spotlight
-------------------------------------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
-------------------------------------------------------------------------------------------

set downloadsFolderAlias to path to downloads folder
set appName to doJavaScriptInSafari("document.getElementById('app_info_name').innerText")

if appName = missing value then
    set appName to doJavaScriptInSafari("document.getElementById('app_info_name_2').innerText")
end if

set newStr to its cngStr:"[\\n\\r]+" intoString:"" inString:appName

set findText to "kMDItemFSName:" & "\"" & appName & "\""

tell application "System Events"
    tell application process "Finder"
        if its visible is false then
            set its visible to true
            delay 0.1
        end if
    end tell
end tell

tell application "Finder"
    try
        set frontWindowTarget to target of front window as alias
        if frontWindowTarget ≠ downloadsFolderAlias then
            open downloadsFolderAlias
            delay 0.2
        end if
    on error
        # Window is probably a search window.
        if name of front window starts with "Searching " then
            # NULL
        else
            error "Problem with front window!"
        end if
    end try
end tell

tell application "System Events"

    

    tell application process "Finder"

        

        set frontmost to true --» •••••

        

        tell front window
            tell toolbar 1
                tell group 6

                    

                    tell (first text field whose subrole is "AXSearchField")

                        

                        set selected to true
                        set focused to true
                        set value to findText

                        

                        perform action "AXConfirm"

                        

                    end tell

                    

                end tell
            end tell
        end tell

        

    end tell
end tell

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on cngStr:findString intoString:replaceString inString:dataString
    set anNSString to current application's NSString's stringWithString:dataString
    set dataString to (anNSString's ¬
        stringByReplacingOccurrencesOfString:findString withString:replaceString ¬
            options:(current application's NSRegularExpressionSearch) range:{0, length of dataString}) as text
end cngStr:intoString:inString:
-------------------------------------------------------------------------------------------
on doJavaScriptInSafari(_javascript_Str)
    try
        tell application "Safari" to do _javascript_ _javascript_Str in front document
    on error e
        error "Error in handler doJavaScriptInSafari() of library NLb!" & return & return & e
    end try
end doJavaScriptInSafari
-------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Lookup Name from App-Page on MacUpdate.com in Downloads Folder with Spotlight
      • From: Christopher Stone <email@hidden>
  • Prev by Date: Re: Applescript and emacs :)
  • Next by Date: Re: Lookup Name from App-Page on MacUpdate.com in Downloads Folder with Spotlight
  • Previous by thread: Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari
  • Next by thread: Re: Lookup Name from App-Page on MacUpdate.com in Downloads Folder with Spotlight
  • Index(es):
    • Date
    • Thread