AppleScript를 통해 Finder 사이드 바 폴더를 어떻게 열 수 있습니까?
-
11-07-2019 - |
문제
SSH를 통해 Mac에서 실행되는 Bash 스크립트가 있습니다. 스크립트에는 특정 네트워크 드라이브가 이미 장착되어야합니다. Mac에서는 Finder의 해당 드라이브에 폴더 "jplemme"을 열어이 드라이브를 장착합니다. 이것은 Mac이 밤에 잠들 때까지 드라이브를 장착합니다.
분명히 SSH를 통해 Finder를 사용할 수 없으므로 GUI를 통해 수행하는 작업을 시뮬레이션하는 사과 스크립트를 만들고 싶습니다. 난 노력 했어:
tell application "Finder"
activate
open "JPLemme"
end tell
다음 오류를받습니다.
execution error: Finder got an error: Can't get "JPLemme". (-1728)
나는 분명한 것을 놓치고 있다고 생각하지만 Google은 저를 실패했습니다. 또한 드라이브를 직접 장착하는 것과 같은 더 나은 솔루션을 기꺼이 즐겁게 해줄 것입니다. 나는 이미 예상치 못한 방식으로 마운트 한 후 Mac이 드라이브를 두 번째로 장착하려고 시도하지 않기 때문에 그 접근법을 피했습니다. (나는 Mac이나 Applescript를 정말 좋아하지 않습니다 ...)
해결책
네트워크 볼륨에는 어떤 종류의 도메인이 부착되어야합니다. 따라서 "jplemme.domain.com". 다음과 같은 코드 덩어리를 사용하여 비밀번호로 보호되는 네트워크 볼륨으로 이동합니다.
tell application "Finder"
try
set theServer to mount volume "smb://path/to/volume" as username "YourUserName" with password "YourPassword"
--Please note here that this is a plain string without any built-in security. Use at your own risk.
on error
set VolumeCount to (get count of disks)
repeat with x from 1 to VolumeCount
set thisVolume to disk x
if name of thisVolume is "JPLemme" then
set theServer to thisVolume
exit repeat
end if
end repeat
end try
end tell
필요에 따라 정리할 수 있지만 이것이 핵심입니다. 행운을 빕니다
다른 팁
그것은 매우 핵심적으로, 실제로 필요한 것은 다음과 같습니다.
Tell Application "Finder"
Mount Volume "smb://username:password@server/sub/directory"
End Tell
그러나 사용되는 것은 주로 네트워크 환경과 반환 된 오류에 달려 있습니다.
제휴하지 않습니다 StackOverflow