Advertisement
wch1zpink

Log_If_App_Is_Background_Only_Library.scpt

Aug 30th, 2021 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. — Place this file in your /Users/YourShortName/Library/Script Libraries/  folder
  2.  
  3. global appName
  4.  
  5. on logAppSetToRunInBackgroundOnly(appName)
  6.     set entryExists to missing value
  7.     set currentDate to (current date) as string
  8.     set theFile to (path to desktop as text) & ".Logz" & ":" & "Background_Only_Apps.log" --value can be changed
  9.     set myName to appName
  10.    
  11.     try
  12.         if myName is not in (paragraphs of (read file theFile) as text) then
  13.             set theText to myName & " was set to run in " & quote & "Background Only" & quote & " mode on " & currentDate
  14.             do shell script "echo " & quoted form of theText & " >> " & quoted form of POSIX path of theFile
  15.         end if
  16.     on error errMsg number errNum
  17.         set theText to myName & " was set to run in " & quote & "Background Only" & quote & " mode on " & currentDate
  18.         do shell script "echo " & quoted form of theText & " >> " & quoted form of POSIX path of theFile
  19.     end try
  20. end logAppSetToRunInBackgroundOnly
  21.  
  22. on removeLogEntry(appName)
  23.     set entryExists to missing value
  24.     set theFile to (path to desktop as text) & ".Logz" & ":" & "Background_Only_Apps.log" --value can be changed
  25.     set myName to appName
  26.    
  27.     do shell script "cat " & quoted form of POSIX path of theFile & " | egrep -v " & ¬
  28.         "'" & myName & "' | pbcopy ; pbpaste > " & quoted form of POSIX path of theFile
  29.    
  30. end removeLogEntry
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement