wch1zpink

Backgrounder Droplet AppleScript

Aug 30th, 2021 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global appName
  2. property fileTypes : {"com.apple.application-bundle"}
  3. property plistFileItem : "  <key>LSUIElement</key>" & linefeed & "  <true/>"
  4. property theLibrary : (path to home folder as text) & "Library:Script Libraries:Log_If_App_Is_Background_Only_Library.scpt"
  5.  
  6. set logBackgroundOnly to load script alias theLibrary
  7.  
  8. activate
  9. set chosenApp to (choose application with prompt ¬
  10.     "Choose  The Application You Want Hidden From The Dock While It Is Running" as alias)
  11.  
  12. tell application "System Events" to set appName to name of chosenApp
  13. set plistFile to ((POSIX path of chosenApp) & "Contents/info.plist") as string
  14. set plistFileContents to (read plistFile)
  15. set plistFileItemExists to plistFileItem is in plistFileContents
  16.  
  17. if plistFileItemExists then
  18.     activate
  19.     set theChoice to button returned of (display dialog ¬
  20.         "Would you like to un-hide " & quote & appName & quote & ¬
  21.         " from the Dock while it's running?" buttons {"Cancel", "Un-Hide"} ¬
  22.         default button 2 cancel button 1 with title "Make A Choice")
  23. else
  24.     activate
  25.     set theChoice to button returned of (display dialog ¬
  26.         "Would you like to hide " & quote & appName & quote & ¬
  27.         " from the Dock while it's running?" buttons {"Cancel", "Hide"} ¬
  28.         default button 2 cancel button 1 with title "Make A Choice")
  29. end if
  30.  
  31. if theChoice is "Hide" then
  32.     tell application "System Events" to tell contents of property list file plistFile ¬
  33.         to make new property list item at end with properties ¬
  34.         {kind:string, name:"LSUIElement", value:true}
  35.    
  36.     try
  37.         run logBackgroundOnly's logAppSetToRunInBackgroundOnly(appName)
  38.     end try
  39.    
  40. else if theChoice is "Un-Hide" then
  41.     tell application "System Events" to tell contents of property list file plistFile ¬
  42.         to make new property list item at end with properties ¬
  43.         {kind:string, name:"LSUIElement", value:false}
  44.    
  45.     try
  46.         run logBackgroundOnly's removeLogEntry(appName)
  47.     end try
  48.    
  49. else
  50.     compileAppScript(chosenApp)
  51.     return
  52. end if
  53.  
  54. compileAppScript(chosenApp)
  55.  
  56. on open of theFiles
  57.     --  Executed when files are dropped on the script
  58.     set logBackgroundOnly to load script alias theLibrary
  59.    
  60.     repeat with chosenApp in theFiles
  61.         tell application "System Events" to set appName to name of chosenApp
  62.         set plistFile to ((POSIX path of chosenApp) & "/Contents/info.plist") as string
  63.         set plistFileContents to (read plistFile)
  64.         set plistFileItemExists to plistFileItem is in plistFileContents
  65.        
  66.         if plistFileItemExists then
  67.             activate
  68.             set theChoice to button returned of (display dialog ¬
  69.                 "Would you like to un-hide " & quote & appName & quote & ¬
  70.                 " from the Dock while it's running?" buttons {"Cancel", "Un-Hide"} ¬
  71.                 default button 2 cancel button 1 with title "Make A Choice")
  72.         else
  73.             activate
  74.             set theChoice to button returned of (display dialog ¬
  75.                 "Would you like to hide " & quote & appName & quote & ¬
  76.                 " from the Dock while it's running?" buttons {"Cancel", "Hide"} ¬
  77.                 default button 2 cancel button 1 with title "Make A Choice")
  78.         end if
  79.        
  80.         if theChoice is "Hide" then
  81.             tell application "System Events" to tell contents of property list file plistFile ¬
  82.                 to make new property list item at end with properties ¬
  83.                 {kind:string, name:"LSUIElement", value:true}
  84.            
  85.             try
  86.                 run logBackgroundOnly's logAppSetToRunInBackgroundOnly(appName)
  87.             end try
  88.            
  89.         else if theChoice is "Un-Hide" then
  90.             tell application "System Events" to tell contents of property list file plistFile ¬
  91.                 to make new property list item at end with properties ¬
  92.                 {kind:string, name:"LSUIElement", value:false}
  93.            
  94.             try
  95.                 run logBackgroundOnly's removeLogEntry(appName)
  96.             end try
  97.            
  98.         else
  99.             compileAppScript(chosenApp)
  100.             return
  101.         end if
  102.        
  103.         compileAppScript(chosenApp)
  104.        
  105.     end repeat
  106. end open
  107.  
  108. to compileAppScript(chosenApp)
  109.     try
  110.         tell application "Script Debugger"
  111.             set theApp to open chosenApp
  112.             delay 0.1
  113.             set succesfulCompile to compile theApp with showing errors
  114.             delay 0.1
  115.             close theApp saving yes
  116.         end tell
  117.     end try
  118.     return succesfulCompile
  119. end compileAppScript
Advertisement
Add Comment
Please, Sign In to add comment