set appNames to {"Finder", "httpd", "System Events", "Mail"}
set AppleScript's text item delimiters to "\\|"
set expression to appNames as string
set AppleScript's text item delimiters to ""
set runningApps to every paragraph of (do shell script "ps -acwx -o command | grep -i " & quoted form of expression & " || echo 'false'")
if runningApps is {"false"} then
tell application "System Events" to shut down
end if
on run
tell application "EyeTV"
if is_recording is false then
tell application "EyeTV" to quit
end if
end tell
delay 15
tell application "Turbo.264 HD"
if isEncoding is false then
tell Application "Turbo.264 HD" to quit
end if
end tell
delay 15
set appNames to {"EyeTV", "Turbo.264 HD"}
set AppleScript's text item delimiters to "\\|"
set expression to appNames as string
set AppleScript's text item delimiters to ""
set runningApps to every paragraph of (do shell script "ps -acwx -o command | grep -i " & quoted form of expression & " || echo 'false'")
if runningApps is {"false"} then
tell application "System Events" to shut down
end if
end run
I get this kind of log:
tell application "EyeTV"
get is_recording
--> false
quit
end tell
tell Application "Turbo.264 HD"
get isEncoding
--> true
end tell
tell current application
do shell script "ps -acwx -o command | grep -i 'EyeTV\\|Turbo.264 HD' || echo 'false'"
--> "EyeTV Helper
Turbo.264 HD"
end tell
Why is EyeTV Helper showing? I can’t find the process from Activity Monitor.
It’s because grep looks if the word fits in the the line instead of matching the whole line. When you give the x option as an argument for grep it will match the entire line and will result only that line that matches exactly.
And yes you should alter the list appNames to the processes you want to lookup. The list runningApps will show you the processes that are running from the appNames list. When none of processes in appNames is running it will return {“false”}.
set appNames to {"Finder", "httpd", "System Events", "Mail", "iTunes"}
set AppleScript's text item delimiters to "\\|"
set expression to appNames as string
set AppleScript's text item delimiters to ""
set runningApps to every paragraph of (do shell script "ps -acwx -o command | grep -ix " & quoted form of expression & " || echo 'false'")
I want to open all files from certain folder with Turbo.264 HD and start encoding.
I made this:
tell application "Turbo.264 HD"
open file "disk:folder"
encode
It’s simple and it works but won’t if folder is empty. If the folder is empty Turbo.264 HD says “…” was not added because it is in an unsupported format and then nothing happens.
I tried to add
delay 10
if isEncoding is false then
tell Application "Turbo.264 HD" to quit
else
encode
end if
The best way is to look if the folder is empty or not before you start encoding
set theFolder to "disk:folder"
set folderIsEmpty to count of (every paragraph of (do shell script "ls " & quoted form of POSIX path of theFolder)) = 0
if you want to check for a certain file extension you can use
set theFolder to "disk:folder" --don't end theFolder with ":"
set theExtension to "txt"
set folderIsEmpty to (count of (every paragraph of (do shell script "ls " & quoted form of POSIX path of theFolder & "/*." & theExtension & " || echo ''"))) = 0
So when folderIsEmpty is true then you won’t start the encoding.