1

I am trying to write an AppleScript to open a Numbers document, which is stored in the Numbers folder on my iCloud drive, so that I can access a cell value and create a reminder with it (or otherwise notify myself of this value).

When I try to access the file directly using the symlink to my iCloud I created in my home folder, Numbers says the file doesn't exist.

I found the following on a blog post, though I am not sure I am using it right.

set the defaultDestinationFolder to "/Users/luketimothy/Desktop"
set filePath to "/Users/luketimothy/Library/" & "Mobile Documents:com~apple~Numbers:Documents:Budget.numbers"


tell application "Numbers"
    activate
    try
        open filePath
    on error

    end try
end tell

This script also results in a "file doesn't exist" error.

I tried copying the file into my Documents folder, but I got the same error (and the file doesn't show up in the Documents folder in finder either, even though if I try to copy it again I am asked if I wish to overwrite)

I can't seem to access the Numbers folder in my iCloud folder from the terminal either, which might allow me to use pwd to get an absolute path.

What can I do? Is there some restriction on access to this Numbers folder?

2

You’re trying to define the filePath variable by combining a Posix path string with an HFS string.

Try defining the filePath variable like this…

set filePath to (path to library folder from user domain as text) & ¬
    "Mobile Documents:com~apple~Numbers:Documents:Budget.numbers"

tell application "Numbers"
    open alias filePath
end tell

OR.. My Personal Preference

property theDocument : "Budget.numbers"

set filePath to ((path to library folder from user domain as text) & ¬
    "Mobile Documents:com~apple~Numbers:Documents:" & theDocument)

tell application "Finder"
    if not (exists of alias filePath) then
        tell current application to display dialog "The File: " & theDocument & ¬
            " Does Not Exist" buttons {"Cancel", "OK"} default button "OK"
        return
    end if
end tell

tell application "Numbers"
    open alias filePath
end tell

If you’re not quite sure how to correctly define a file path, you can always use the following Apple Script code in a separate script editor document to correctly retrieve the file paths

set filePathAsAlias to (choose file with prompt "choose file") -- Returns The File Path As An Alias

OR

set posixPathOffilePath to POSIX path of (choose file with prompt "choose file") -- Returns The POSIX Path Of The File
5
  • 1
    A slightly more preferable way to reference the user's library folder would be path to the library folder from the user domain [as text] where as text is optional in case one just wants the (HFS) file path instead of the default alias object. – CJK Oct 25 '19 at 21:27
  • 1
    @CJK Great suggestion and this way it’s not “hard coded” with the exception of the actual file name (which could be set in a separate variable and that variable added to the filePath variable) – wch1zpink Oct 25 '19 at 21:53
  • @wch1zpink is (path to library folder from user domain as text) literally what I enter? I found this code like this and thought I was supposed to replace it with a path... – Luke Oct 26 '19 at 16:40
  • 1
    @Luke . The AppleScript code I posted is exactly how you need it to be – wch1zpink Oct 26 '19 at 16:44
  • @wch1zpink I see, it works now. Thank you! – Luke Oct 27 '19 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .