터미널에서 osascript로 cat 출력 사용 싶지만 표시하려는 텍스트가

터미널에서 osascript를 사용하여 알림을 표시하고 싶지만 표시하려는 텍스트가 텍스트 파일에 저장됩니다. 알림에 해당 텍스트를 표시하려면 어떻게해야합니까?



답변

Bash 셸에서 파일을 사용하여 파일을 읽고 cat대체 파일 로 넣을 수 있습니다.

다음과 같은 것 :

osascript -e "display notification \"$(cat /tmp/foo.txt)\" with title \"hello\""

(분명히 무언가를 /tmp/foo.txt먼저 넣으십시오 echo "Hello world" > /tmp/foo.txt)


답변

기본적으로 파일 내용을 변수로 먼저 읽어야합니다. 이를 수행하는 방법에는 여러 가지가 있습니다.

text=$(< TEXTFILE)
osascript ... "$text"

답변

내가 처음 게시 한 질문에 대한 완전한 soloution은 다음과 같습니다.

set listOfCommand to (read POSIX file "path-to/command.txt")
  tell application "Terminal"
    do script listOfCommand
    delay 1
    quit
  end tell
set listOfShows to (read POSIX file "path-to/dump.txt")
 tell application "Safari"
    display notification listOfShows with title "Downloads:"
 end tell