https://github.com/user-attachments/assets/829f4282-cde6-4ac4-bb59-3e2867456d89
Open finicky-default-browser in Script Kit
// Name: Finicky Switch Default Browser// Description: Switches the default browser in Finicky config// Author: Strajkimport '@johnlindquist/kit'import fs from 'fs'let finickyPath = home('.finicky.js')// Check if Finicky config existsif (!fs.existsSync(finickyPath)) {await div({html: `<div class="p-4 bg-red-100 text-red-800"><h3 class="font-bold">Finicky not installed</h3><p>Or at least, ~/.finicky.js was not found</p><p>Please install Finicky first: <code>brew install finicky</code></p></div>`})exit()}// Resolve symlink if finickyPath is a symlink, e.g. /Users/strajk/.finicky.js -> /Users/strajk/Projects/setup/home/.finicky.jsfinickyPath = fs.realpathSync(finickyPath)// List of possible browsers to select fromconst possibleBrowsers = ['Google Chrome','Google Chrome Dev','Firefox','Firefox Developer Edition','Safari','Opera','Brave','Microsoft Edge','Browserosaurus',]try {// Read the content of the Finicky configuration fileconst configContent = await readFile(finickyPath, 'utf8')// Log number of lines in config fileconst numLines = configContent.split('\n').lengthconsole.log('===' + new Date().toISOString())console.log(`Config file has ${numLines} lines`)// Regular expression to find the default browser setting in the configconst defaultBrowserRegex = /defaultBrowser: "([^"]*?)".?/const match = defaultBrowserRegex.exec(configContent)const currentDefaultBrowser = match ? match[1] : nullif (!currentDefaultBrowser) {console.log('No default browser found')exit()}// Prompt the user to select a new default browserconst selectedBrowser = await arg({placeholder: 'Select a default browser',choices: possibleBrowsers,hint: 'Current default browser: ' + currentDefaultBrowser,})// Create a new comment based on the previously selected browserconst newComment = currentDefaultBrowser ? ` Previously: ${currentDefaultBrowser}` : ''// Replace the old default browser setting with the new one, including the updated commentconst newConfigContent = configContent.replace(defaultBrowserRegex,`defaultBrowser: "${selectedBrowser}", //${newComment}`)// Write the updated content back to the Finicky configuration fileawait writeFile(finickyPath, newConfigContent)// Display a notification to confirm the updateawait notify({title: 'Finicky Config Updated',body: `Default browser set to ${selectedBrowser}`,})} catch (error) {// Handle errors, such as the config file not existingconsole.error(`Failed to update Finicky config: ${error}`)await notify({title: 'Finicky Config Update Failed',body: `Error: ${error}`,})}