Search code examples
applescripticloud

Open iCloud in current Finder window with AppleScript


I'm trying to open iCloud in the current Finder window/tab. The below AppleScript works with any other folder.

How can I open iCloud in the current Finder window with AppleScript?

tell application "Finder"
    reopen
    activate
    set p to "~/Library/Mobile Documents/"
    set target of Finder window 1 to POSIX file p
end tell

Solution

  • The script doesn't work because the Finder is not able to expand the tilde in POSIX paths.

    This is an alternative with a relative path.

    set userLibraryFolder to path to library folder from user domain
    tell application "Finder"
        reopen
        activate
        set iCloudDriveFolder to folder "iCloud Drive" of folder "Mobile Documents" of userLibraryFolder
        set target of Finder window 1 to iCloudDriveFolder
    end tell