2016-09-15 2 views
2

특정 이메일 주소로 많은 vCard를 수신합니다. vcards를 메일 규칙과 AppleScript를 통해 내 연락처에 자동으로 추가하려고합니다.메일 규칙 및 AppleScript로 연락처에 vcard 추가

나는 많은 것을 수색하고 무언가를 발견했다. 나는 그것을 약간 수정했다. 그리고 개장과 추가 과정이 잘 작동합니다. 하지만 파일을 선택할 때만. 파일을 메일 메시지에서 변수로 가져올 수 없습니다. 나는 그것을 시도했지만 작동하지 않습니다. I 라인 1, 2, 3을 삭제 한 다음 그것을 작동합니다 "thefile 파일을 선택하도록 설정"4 번 작성하는 경우

tell application "Mail" 
    set att to attachment 
end tell 
set thefile to att 
tell application "Contacts" 
    activate 
    open thefile 
end tell 
tell application "System Events" to keystroke return 

- 나는 파일을 선택하는 경우 :

여기에 지금까지 내 코드입니다. 그러나 처음 세 줄은 어떤 것을 시도했지만 성공하지 못했습니다. 제 질문은 메시지에서 파일을 가져 오는 방법입니다.

너의 진심 크리스 감사

해결 방법 : 이메일에서 첨부

set Dest to ((path to desktop folder) as string) 
tell application "Finder" to make new folder in Dest with properties {name:"TempFiles"} -- create TempFiles folder 
Set Dest to Dest & "TempFiles:" 
tell application "Mail" 
activate -- not sure is mandatory, but I prefer to see selected mails !! 
set ListMessage to selection -- get all selected messages 
repeat with aMessage in ListMessage -- loop through each message selected 
    set AList to every mail attachment of aMessage -- get all attachements 
    repeat with aFile in AList -- for each attachement 
     if (downloaded of aFile) then 
      set Filepath to Dest & (name of aFile) 
      do shell script "touch " & (quoted form of (POSIX path of Filepath)) -- required because "Save" only works with existing file ! 
      save aFile in (Filepath as alias) as native format 
     end if 
    end repeat -- next file 
end repeat -- next message 
end tell 

tell application "Finder" to set CardList to every file of folder Dest whose name extension is {"vcf"} 
tell application "Contacts" 
activate 
repeat with aCard in CardList 
    open aCard 
    delay 1 
    tell application "System Events" to keystroke return 
end repeat 
end tell 
delay 2 
-- tell application "Finder" to delete folder Dest 

답변

0

파일은 응답 '다른 이름으로 저장 "명령 만에하지' '개방. 그런 다음 첨부 파일을 저장하고 나중에 다음 애플리케이션으로 이동해야합니다 (사례에서 '연락처'추가).

첨부 파일은 메시지의 '메일 첨부 파일'목록의 구성원입니다. 첨부 된 파일이 많을 수 있음을 명심하십시오.

또한 'downloaded'속성이 true 인 경우에만 첨부 파일을 저장할 수 있습니다.

마지막으로 Snow Leopard에서 잘 작동하는 "저장"명령은 El Capitain에서 동일하게 작동하지 않습니다 : 저장하기 전에 저장해야하는 파일은 ... "저장"해야합니다. 이것이 바로 "touch"명령을 추가하여 (tempFiles 폴더에 항목을 작성하는 것) 먼저 작성하는 이유입니다.

연락처의 유효성을 검사 할 Enter 키가있는 열린 vCard를 스크립트 하단에 추가하십시오. 컴퓨터에서 카드를 처리하기 위해 잠시 기다리려면 지연을 추가해야 할 수도 있습니다.

키가 깨진 경우 작동하지 않는 경우 시스템 환경 설정 접근성 설정을 확인하여 컴퓨터에서 스크립트로 Mac을 제어 할 수있게하십시오.

가능한 한 많은 의견을 추가하여 분명히 ... 너무 많을 수 있습니다!

set Dest to ((path to desktop folder) as string) 
tell application "Finder" to make new folder in Dest with properties {name:"TempFiles"} -- create TempFiles folder 
Set Dest to Dest & "TempFiles:" 
tell application "Mail" 
activate -- not sure is mandatory, but I prefer to see selected mails !! 
set ListMessage to selection -- get all selected messages 
repeat with aMessage in ListMessage -- loop through each message selected 
    set AList to every mail attachment of aMessage -- get all attachements 
    repeat with aFile in AList -- for each attachement 
     if (downloaded of aFile) then 
      set Filepath to Dest & (name of aFile) 
      do shell script "touch " & (quoted form of (POSIX path of Filepath)) -- required because "Save" only works with existing file ! 
      save aFile in (Filepath as alias) as native format 
     end if 
    end repeat -- next file 
end repeat -- next message 
end tell 

tell application "Finder" to set CardList to every file of folder Dest whose name extension is {"vcf"} 
tell application "Contacts" 
activate 
repeat with aCard in CardList 
    open aCard 
    tell application "System Events" to keystroke return 
end repeat 
end tell 

-- tell application "Finder" to delete folder Dest 

당신이 볼 수 있듯이, 내가 선택한 이메일도 연락이 처리 할 수없는 파일의 다른 유형을 포함 할 경우에 대비 ... 확장 'VCD'만 파일이 임시 폴더의 내용을 필터링 할 수 있습니다.

스크립트 끝에서 임시 폴더를 삭제합니다. 그러나 테스트 할 때까지이 마지막 줄을 주석으로 만 지정하십시오 (보다 안전합니다).

+0

감사합니다 - 스크립트가 저에게 효과적입니다. 하지만 난 텔 응용 프로그램 "연락처" 이 개방 thefile 끝이 부품을 반환 키 입력하려면 "시스템 이벤트"를 TELL 응용 프로그램을 말해 활성화를 배치해야합니까? 대본이 끝나거나 끝나면? 아무것도 작동하지 않지만 독립 실행 형 스크립트는 완벽하게 작동합니다. –

+0

방금 ​​"vCard 열기"및 최대 임시 폴더 삭제를 포함한 전체 스크립트로 내 스크립트를 업데이트합니다. – pbell

+0

고맙습니다.하지만 TempFiles 폴더에서는 작동하지 않습니다. 모든 파일을 바탕 화면 폴더에 있지만 하위 폴더에는 다운로드 할 수 없습니다 ... 그리고 시스템 이벤트 키 스트로크는 더 이상 작동하지 않습니다 ... 어쩌면 내가 직접 고칠 수 있습니다 ... 시도 했습니까? 컴퓨터에 있나요? –

관련 문제