터미널에서 osascript로 cat 출력 사용


2

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

답변:


2

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

다음과 같은 것 :

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

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


2

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

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

하나의 라이너로 할 수있는 방법이 없습니까?
Kwright02

물론, 변수를 $(...)구문으로 대체하십시오
nohillside

2

내가 처음 게시 한 질문에 대한 완전한 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
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.