How to get the default web browser of current user through AppleScript ?

Hi everybody!

I contact you for the following question:

How to get the default web browser of current user through AppleScript?

I would like to create a script that checks the default web browser of the person using my program.

Also, I would like to check what is the default download folder of the found browser.


Why would you do that? You might say.


It's quite simple, I would like to find a file with a specific name in the download folder, but I actually realize that it's not necessarily the ideal solution...

That's why, if possible, I would simply like to search all files on all mac hard drives (internal or external) of a file name or keyword (the keyword "Paladium" in my case) and save the path in a variable ("paladiumLauncherPath" in my case).


Sorry for the quality of the English in my message, I am French and I used an automatic translator to send it to you.


I would like to point out that I am new to Apple scripts.


Here's what I've already tried to find the default download folder for Safari (code found on an old topic in this forum):

tell application "Finder"
	set paladiumLauncherPath to do shell script "defaults read com.apple.safari DownloadsPath"
	if paladiumLauncherPath = "~" or paladiumLauncherPath starts with "~/" then ¬
		set paladiumLauncherPath to text 1 thru -2 of POSIX path of (path to home folder) & rest of characters of paladiumLauncherPath
	open POSIX file paladiumLauncherPath as alias
	activate
end tell


But I'm lucky to get this error message:

error "Erreur dans Finder : 2019-02-03 13:57:15.548 defaults[15168:407110] 

The domain/default pair of (com.apple.safari, DownloadsPath) does not exist" number 1


-Milan

MacBook Air 13", 10.14

Posted on Feb 3, 2019 5:01 AM

Reply

Similar questions

5 replies

Feb 3, 2019 9:47 AM in response to Milan Lefort

Your code to get the Safari DownloadsPath requires com.apple.Safari, not com.apple.safari. There is no equivalent for Firefox.


The following AppleScript/Objective-C solution gets the current default browser name (e.g. Safari, Firefox, etc.). It has been tested on macOS High Sierra 10.13.6 and macOS Mojave 10.14.3. Safari, Firefox, and Google Chrome browsers were installed and detected when set as default browsers.


-- default_browser.applescript
-- Show currently set default browser. Change this via System Preferences : General panel
-- VikingOSX, 2019-02-03, Apple Support Communities, No warranty expressed or implied.

use framework "Cocoa"
use AppleScript version "2.4" -- Yosemite 10.10 or later
use scripting additions

property NSURL : a reference to current application's NSURL
property NSWorkspace : a reference to current application's NSWorkspace
property NSFileManager : a reference to current application's NSFileManager

set any_url to "http://www.apple.com"

display dialog my default_browser(any_url)
return

on default_browser(a_url)
	set the_url to NSURL's URLWithString:a_url
	set theApp to ((NSWorkspace's sharedWorkspace())'s URLForApplicationToOpenURL:the_url) as text
	return ((NSFileManager's alloc()'s init())'s displayNameAtPath:(POSIX path of theApp)) as text
end default_browser


Feb 3, 2019 10:04 AM in response to Milan Lefort

There are several million files on your startup disk. I would take advantage of Spotlight to hit an index, and not expend huge resources scouring the drive with file I/O.


First, configure Finder's Preferences:

  1. General
    1. New Finder windows show: <house icon with your short user name>
  2. Advanced
    1. When performing a search: Search the Current Folder
  3. From the Finder's View menu, Show Path Bar.


Next, in System Preferences : Spotlight : Search Results panel

  1. Select the categories that represent your searched file type


Now in a Finder window's search field, or Spotlight itself, enter the following:


name:pala


This will find all indexed file categories where the filename contains the string "pala."


use framework "Cocoa"
use AppleScript version "2.4"
use scripting additions

property NSWorkspace : a reference to current application's NSWorkspace

set query to "name:pala"

-- display a Finder window with the files that the query found
set result_code to (NSWorkspace's sharedWorkspace)'s showSearchResultsForQueryString:query
return


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to get the default web browser of current user through AppleScript ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.