Skip to content

Commit

Permalink
Move scripts/clean-launch-services-database to tools/clean-launch-ser…
Browse files Browse the repository at this point in the history
…vices-database
  • Loading branch information
tekezo committed Nov 18, 2023
1 parent 5719c1b commit 42e84c8
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ clean:
$(MAKE) clean-launch-services-database

clean-launch-services-database:
bash scripts/clean-launch-services-database.sh
$(MAKE) -C tools/clean-launch-services-database

gitclean:
git clean -f -x -d
Expand Down
15 changes: 0 additions & 15 deletions scripts/clean-launch-services-database.sh

This file was deleted.

55 changes: 0 additions & 55 deletions scripts/clean-launch-services-database.swift

This file was deleted.

1 change: 1 addition & 0 deletions tools/clean-launch-services-database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.build
2 changes: 2 additions & 0 deletions tools/clean-launch-services-database/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
swift run
14 changes: 14 additions & 0 deletions tools/clean-launch-services-database/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version: 5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "clean-launch-services-database",
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "clean-launch-services-database"),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let bundleIdentifiers = [
// Karabiner-Elements
"org.pqrs.Karabiner-EventViewer",
"org.pqrs.Karabiner-Menu",
"org.pqrs.Karabiner-MultitouchExtension",
"org.pqrs.Karabiner-NotificationWindow",
"org.pqrs.Karabiner-Elements.Settings",

// Karabiner-DriverKit-VirtualHIDDevice
"org.pqrs.HIDManagerTool",
"org.pqrs.Karabiner-DriverKit-VirtualHIDDeviceClient",
"org.pqrs.Karabiner-VirtualHIDDevice-Manager",
"org.pqrs.virtual-hid-device-service-client",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import AppKit

//
// The built application is automatically registered in the Launch Services database.
// This means that unwanted entries such as */build/Release/*.app will be registered.
//
// Then, the names displayed in Background items of Login Items System Settings refer to the launch services database.
// If the path of the built application is referenced, the application name may not be taken properly and the developer name may appear in Login Items.
//
// To avoid this problem, unintended application entries should be removed from the database.
// This script removes such entries which includes /Build/ or /build/ in the file path.
//

if #available(macOS 13.0, *) {
let lsregisterCommandPath =
"/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
let deleteTargetPathRegex = #/
/build/ |
/Build/
/#

for bundleIdentifier in bundleIdentifiers {
print("clean-launch-services-database \(bundleIdentifier)...")

let urls = NSWorkspace.shared.urlsForApplications(withBundleIdentifier: bundleIdentifier)

for url in urls {
let path = url.path
if path.matches(of: deleteTargetPathRegex).count > 0 {
print("unregister from the Launch Services database: \(path)")

let process = Process()
process.launchPath = lsregisterCommandPath
process.arguments = [
"-u",
path,
]

process.launch()
process.waitUntilExit()
}
}
}
}

0 comments on commit 42e84c8

Please sign in to comment.