• 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
Software Installer – Finding the Local Application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Software Installer – Finding the Local Application


  • Subject: Software Installer – Finding the Local Application
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 29 Mar 2017 04:00:45 -0500

Hey Folks,

I have a fairly involved script that automates installing software from a .dmg if it's already on my system.

The script currently:

* Requires me to find the app on the local disk and open its container folder (which I do very quickly with LaunchBar).
* Mounts the dmg file selected in the Finder.
* Matches the contained app with open windows in the Finder.
* Trashes the local app.
* Replaces it with the new one on the dmg.

At the moment I'm prototyping some code to automate finding the app on the local disk – which will be faster and safer than what I'm doing now.

Shane – can AppleScriptObjC substitute for the hdiutil in mounting the disk AND saying “yes” to any licensing?

Similarly to this:

set shCmd to "echo \"y\" | hdiutil mount " & qf(diskImgPosixPath) & " 2> /dev/null"
set imgVolPath to do shell script shCmd

The script is working as is, so I'm going to share it at this point.

Note – this code doesn't mount the dmg – you have to do that manually.

Enjoy.

--
Best Regards,
Chris

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/03/29 03:33
# dMod: 2017/03/29 03:33 
# Appl: Software Installer
# Task: Attempt to find an app on a DMG in the /Applications folder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Finder, @Software, @Installer, @DMG
------------------------------------------------------------------------------
use framework "Foundation"
use framework "AppKit"
use scripting additions
------------------------------------------------------------------------------

set theApp to missing value

tell application "Finder"
    set frontWinID to id of front window
    tell window id frontWinID
        set winTarget to its target

        

        if winTarget's class is disk then
            set appsOnDiskList to my listFilesByExtension:{"app"} fromDirectory:(winTarget as alias)
        else
            error "Front window is NOT a disk!"
        end if

        

        tell appsOnDiskList
            if its length is 1 then
                set theApp to (item 1 of it) as alias
            else
                error "Too many applications found on disk!"
            end if
        end tell

        

        set appBundleID to id of theApp

        

    end tell
end tell

if theApp ≠ missing value then

    

    set theAppPath to qf(POSIX path of theApp)
    set shCMD to "mdfind -onlyin /Applications/ 'kMDItemCFBundleIdentifier == \"" & appBundleID & "\"c'"
    set theAppLocalPath to do shell script shCMD

    

    if length of (paragraphs of theAppLocalPath) = 1 then
        set theAppLocalAlias to alias POSIX file theAppLocalPath
    end if

    

    tell application "Finder"
        activate
        set localAppParentFolder to parent of theAppLocalAlias as alias
        open localAppParentFolder
    end tell

    

end if

------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on listFilesByExtension:listOfExtensions fromDirectory:sourceFolder
    set sourceFolder to POSIX path of sourceFolder
    set fileManager to current application's NSFileManager's defaultManager()
    set aURL to current application's |NSURL|'s fileURLWithPath:sourceFolder
    set directoryContents to fileManager's contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:0 |error|:(missing value)
    set foundItemList to current application's NSPredicate's predicateWithFormat_("pathExtension.lowercaseString IN %@", listOfExtensions)
    set foundItemList to directoryContents's filteredArrayUsingPredicate:foundItemList
    return foundItemList as list -- furls
end listFilesByExtension:fromDirectory:
------------------------------------------------------------------------------
on qf(_text)
    return (quoted form of _text)
end qf
------------------------------------------------------------------------------



 _______________________________________________
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: Software Installer – Finding the Local Application
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Sierra mail problem
  • Next by Date: Applescript Editor → Script Editor
  • Previous by thread: Re: Sierra mail problem
  • Next by thread: Re: Software Installer – Finding the Local Application
  • Index(es):
    • Date
    • Thread