launchctlのplistファイルを0バイト(空)にしてロックする
| 固定リンク
行番号 | ソース |
---|---|
001 | #!/bin/bash |
002 | #com.cocolog-nifty.quicktimer.icefloe |
003 | ################################################# |
004 | ###管理者インストールしているか?チェック |
005 | USER_WHOAMI=$(/usr/bin/whoami) |
006 | /bin/echo "実行ユーザー(whoami): $USER_WHOAMI" |
007 | if [ "$USER_WHOAMI" != "root" ]; then |
008 | /bin/echo "このスクリプトを実行するには管理者権限が必要です。" |
009 | /bin/echo "sudo で実行してください" |
010 | ### path to me |
011 | SCRIPT_PATH="${BASH_SOURCE[0]}" |
012 | /bin/echo "/usr/bin/sudo \"$SCRIPT_PATH\"" |
013 | /bin/echo "↑を実行してください" |
014 | exit 1 |
015 | else |
016 | ###実行しているユーザー名 |
017 | CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }') |
018 | /bin/echo "コンソールユーザー(scutil): $CONSOLE_USER" |
019 | ###実行しているユーザー名 |
020 | HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}') |
021 | /bin/echo "実行ユーザー(HOME): $HOME_USER" |
022 | ###logname |
023 | LOGIN_NAME=$(/usr/bin/logname) |
024 | /bin/echo "ログイン名(logname): $LOGIN_NAME" |
025 | ###UID |
026 | USER_NAME=$(/usr/bin/id -un) |
027 | /bin/echo "ユーザー名(id): $USER_NAME" |
028 | ###STAT |
029 | STAT_USR=$(/usr/bin/stat -f%Su /dev/console) |
030 | /bin/echo "STAT_USR(console): $STAT_USR" |
031 | fi |
032 | |
033 | ######################################## |
034 | ##"system", "local", "network" "user" |
035 | /bin/echo "チェック開始" |
036 | STR_CMD_PATH="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister" |
037 | #書き出し先フォルダを作っておいて |
038 | STR_SAVE_DIR_PATH="/Users/${STAT_USR}/Documents/Apple/Lsregister" |
039 | /usr/bin/sudo -u "$STAT_USR" /bin/mkdir -p "$STR_SAVE_DIR_PATH" |
040 | /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "$STR_SAVE_DIR_PATH/_このフォルダは削除しても大丈夫です.txt" |
041 | STR_DATE_NO=$(/bin/date "+%m%d%H%M%Y") |
042 | #チェック |
043 | "$STR_CMD_PATH" -lint |
044 | #ダンプします |
045 | STR_SAVE_FILE_NAME="$STR_DATE_NO""_all.txt" |
046 | STR_SAVE_FILE_PATH="${STR_SAVE_DIR_PATH}/${STR_SAVE_FILE_NAME}" |
047 | "$STR_CMD_PATH" -dump | /usr/bin/sudo -u "$STAT_USR" tee -a "$STR_SAVE_FILE_PATH" >/dev/null |
048 | #UTIを抽出 |
049 | STR_EXP_FILE_NAME="$STR_DATE_NO""_UTI.txt" |
050 | STR_EXP_FILE_PATH="${STR_SAVE_DIR_PATH}/${STR_EXP_FILE_NAME}" |
051 | /usr/bin/grep '^type id' "$STR_SAVE_FILE_PATH" | /usr/bin/sudo -u "$STAT_USR" tee -a "$STR_EXP_FILE_PATH" >/dev/null |
052 | #名前とパスを抽出 |
053 | STR_EXP_FILE_NAME="$STR_DATE_NO""_NAME.txt" |
054 | STR_EXP_FILE_PATH="${STR_SAVE_DIR_PATH}/${STR_EXP_FILE_NAME}" |
055 | /usr/bin/grep -E "path:|name: | more" "$STR_SAVE_FILE_PATH" | /usr/bin/sudo -u "$STAT_USR" tee -a "$STR_EXP_FILE_PATH" >/dev/null |
056 | # |
057 | /bin/echo "再構築を実行しますか?" |
058 | /bin/echo "Yを選択すると再起動します" |
059 | /bin/echo "未保存の書類がある場合はNを入力してください" |
060 | /bin/echo "Nを選択するとこのまま処理を終了します" |
061 | /bin/echo "(Y/N)" |
062 | |
063 | read -r STR_USER_ANS |
064 | # 入力に基づいて処理を分岐 |
065 | if [[ "$STR_USER_ANS" =~ ^[Yy]$ ]]; then |
066 | /bin/echo "lsregisterを削除してリセットします" |
067 | /bin/sync |
068 | sleep 1 |
069 | /bin/sync |
070 | sleep 1 |
071 | /usr/sbin/purge |
072 | sleep 1 |
073 | "$STR_CMD_PATH" -delete |
074 | "$STR_CMD_PATH" -kill |
075 | /sbin/shutdown -r now |
076 | elif [[ "$STR_USER_ANS" =~ ^[Nn]$ ]]; then |
077 | /bin/echo "処理を終了しますa" |
078 | exit 0 |
079 | else |
080 | /bin/echo "処理を終了しますb" |
081 | exit 1 |
082 | fi |
AppleScriptで生成しました |
| 固定リンク
| 固定リンク
コマンドは
lsregister
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
データ
マスターはSQLでパスは
/var/folders/XX/XXXXXXXXXXXXXXXX/0/com.apple.LaunchServices.dv/
通常セキュリティ上『アクセス権が無い』特殊なファイル
自動生成されるので、不具合発生時には削除しても『まぁ』大丈夫
ユーザードメインでは
SQLファイルが
$HOME/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2
PLISTが
$HOME/Library/Preferences/com.apple.LaunchServices にあります
lsregister: [OPTIONS] [ <path>... ]
        [ -apps <domain>[,domain]... ]
        [ -libs <domain>[,domain]... ]
        [ -all <domain>[,domain]... ]
Paths are searched for applications to register with the Launch Service database.
Valid domains are "system", "local", "network" and "user". Domains can also
be specified using only the first letter.
-delete Delete the Launch Services database file. You must then reboot!
-kill     Reset the Launch Services database before doing anything else
-seed     If database isn't seeded, scan default locations for applications and libraries to register
-lint     Print information about plist errors while registering bundles
-lazy n Sleep for n seconds before registering/scanning
-r       Recursive directory scan, do not recurse into packages or invisible directories
-R       Recursive directory scan, descending into packages and invisible directories
-f       force-update registration even if mod date is unchanged
-u       unregister instead of register
-v       Display progress information
-gc   Garbage collect old data and compact the database
-dump [table] Display full database contents after registration
-h       Display this help
sh-3.2$
sh-3.2$
sh-3.2$
sh-3.2$
sh-3.2$ /usr/bin/sqlite3 $HOME/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2
SQLite version 3.37.0 2021-12-09 01:34:53
Enter ".help" for usage hints.
sqlite>
sqlite>
sqlite> .tables
LSQuarantineEvent
sqlite> .mode column
sqlite> select * from LSQuarantineEvent;
LSQuarantineEventIdentifier   LSQuarantineTimeStamp LSQuarantineAgentBundleIdentifier LSQuarantineAgentName LSQuarantineDataURLString
この後ものすごい量のデータが出ます
                                                                       
mkdir -pm 700 $HOME/bin
ln -s /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister $HOME/bin/lsregister
$HOME/bin/lsregister -lint com.tinyspeck.slackmacgap
$HOME/bin/lsregister -delete -r -domain user
$HOME/bin/lsregister -delete -r -domain local
$HOME/bin/lsregister -delete -r -domain network
$HOME/bin/lsregister -delete -r -domain system
$HOME/bin/lsregister -kill -r -domain user
$HOME/bin/lsregister -kill -r -v -f -domain user
$HOME/bin/lsregister -kill -r -domain local
$HOME/bin/lsregister -kill -r -domain network
$HOME/bin/lsregister -kill -r -domain system
$HOME/bin/lsregister -seed -r -v -f -domain user
$HOME/bin/lsregister -seed -r -domain local
$HOME/bin/lsregister -seed -r -domain network
$HOME/bin/lsregister -seed -r -domain system
$HOME/bin/lsregister -lint -r -v -f -domain -apps user
$HOME/bin/lsregister -lint -r -domain -all local
$HOME/bin/lsregister -lint -r -domain -all network
$HOME/bin/lsregister -lint -r -domain -all system
$HOME/bin/lsregister -seed -r -v -f -domain -apps user
$HOME/bin/lsregister -seed -r -v -f -domain -libs user
$HOME/bin/lsregister -seed -r -v -f -domain -all user
$HOME/bin/lsregister -dump -r -v -f -domain -apps user | grep uti:
$HOME/bin/lsregister -dump -r -v -f -domain -apps user | grep "type id:"
$HOME/bin/lsregister -dump -r -v -f -domain -apps user | grep "claim id:"
| 固定リンク
全てのアプリケーションを取得するなら
こちらは書き方が違うだけ
| 固定リンク
Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom