Skip to main content
Fix inaccuracy in description
Source Link
pikappa
  • 103
  • 3

According to the dictionary for Image Events, the open verb is supposed to return a document object. This is also how it's used in multiple online examples.

However, when I try to use it, the script correctlycorrectly opens the file in Preview, butand does not return anything. Even when I try the following example, from Apple's own documentation, I get a "Can’t get properties of missing value." number -1728 from properties of missing value.

How are you meant to get an image object from an existing file in order to manipulate it with other actions from Image Events?

I'm on Big Sur 11.6.2 in case this doesn't affect older/newer releases.

-- Prompt for an image
set theImageFile to choose file of type "public.image" with prompt ""

-- Launch Image Events
tell application "Image Events"
    launch
    
    -- Open the image
    set theImage to open theImageFile
    
    -- Read the image's properties
    tell theImage
        properties
        --> {color space:RGB, image file:file "Macintosh HD:Users:YourUserName:Desktop:My Image.png" of application "Image Events", bit depth:millions of colors, dimensions:{293, 252}, location:folder "Macintosh HD:Users:YourUserName:Desktop:" of application "Image Events", embedded profile:profile "Thunderbolt Display" of image "My Image.png" of application "Image Events", file type:PNG, class:image, name:"My Image.png", resolution:{72.0, 72.0}}
        
        -- Read the image's resolution
        resolution
        --> {72.0, 72.0}
        
        -- Read the image's type
        file type
        --> PNG
        
        -- Read the name of the image's embedded profile
        name of embedded profile
        --> "Thunderbolt Display"
    end tell
end tell

According to the dictionary for Image Events, the open verb is supposed to return a document object. This is also how it's used in multiple online examples.

However, when I try to use it, the script correctly opens the file in Preview, but does not return anything. Even when I try the following example, from Apple's own documentation, I get a "Can’t get properties of missing value." number -1728 from properties of missing value.

How are you meant to get an image object from an existing file in order to manipulate it with other actions from Image Events?

I'm on Big Sur 11.6.2 in case this doesn't affect older/newer releases.

-- Prompt for an image
set theImageFile to choose file of type "public.image" with prompt ""

-- Launch Image Events
tell application "Image Events"
    launch
    
    -- Open the image
    set theImage to open theImageFile
    
    -- Read the image's properties
    tell theImage
        properties
        --> {color space:RGB, image file:file "Macintosh HD:Users:YourUserName:Desktop:My Image.png" of application "Image Events", bit depth:millions of colors, dimensions:{293, 252}, location:folder "Macintosh HD:Users:YourUserName:Desktop:" of application "Image Events", embedded profile:profile "Thunderbolt Display" of image "My Image.png" of application "Image Events", file type:PNG, class:image, name:"My Image.png", resolution:{72.0, 72.0}}
        
        -- Read the image's resolution
        resolution
        --> {72.0, 72.0}
        
        -- Read the image's type
        file type
        --> PNG
        
        -- Read the name of the image's embedded profile
        name of embedded profile
        --> "Thunderbolt Display"
    end tell
end tell

According to the dictionary for Image Events, the open verb is supposed to return a document object. This is also how it's used in multiple online examples.

However, when I try to use it, the script correctly opens the file in Preview, and does not return anything. Even when I try the following example, from Apple's own documentation, I get a "Can’t get properties of missing value." number -1728 from properties of missing value.

How are you meant to get an image object from an existing file in order to manipulate it with other actions from Image Events?

I'm on Big Sur 11.6.2 in case this doesn't affect older/newer releases.

-- Prompt for an image
set theImageFile to choose file of type "public.image" with prompt ""

-- Launch Image Events
tell application "Image Events"
    launch
    
    -- Open the image
    set theImage to open theImageFile
    
    -- Read the image's properties
    tell theImage
        properties
        --> {color space:RGB, image file:file "Macintosh HD:Users:YourUserName:Desktop:My Image.png" of application "Image Events", bit depth:millions of colors, dimensions:{293, 252}, location:folder "Macintosh HD:Users:YourUserName:Desktop:" of application "Image Events", embedded profile:profile "Thunderbolt Display" of image "My Image.png" of application "Image Events", file type:PNG, class:image, name:"My Image.png", resolution:{72.0, 72.0}}
        
        -- Read the image's resolution
        resolution
        --> {72.0, 72.0}
        
        -- Read the image's type
        file type
        --> PNG
        
        -- Read the name of the image's embedded profile
        name of embedded profile
        --> "Thunderbolt Display"
    end tell
end tell
Source Link
pikappa
  • 103
  • 3

How do you use the open verb in Image Events using AppleScript?

According to the dictionary for Image Events, the open verb is supposed to return a document object. This is also how it's used in multiple online examples.

However, when I try to use it, the script correctly opens the file in Preview, but does not return anything. Even when I try the following example, from Apple's own documentation, I get a "Can’t get properties of missing value." number -1728 from properties of missing value.

How are you meant to get an image object from an existing file in order to manipulate it with other actions from Image Events?

I'm on Big Sur 11.6.2 in case this doesn't affect older/newer releases.

-- Prompt for an image
set theImageFile to choose file of type "public.image" with prompt ""

-- Launch Image Events
tell application "Image Events"
    launch
    
    -- Open the image
    set theImage to open theImageFile
    
    -- Read the image's properties
    tell theImage
        properties
        --> {color space:RGB, image file:file "Macintosh HD:Users:YourUserName:Desktop:My Image.png" of application "Image Events", bit depth:millions of colors, dimensions:{293, 252}, location:folder "Macintosh HD:Users:YourUserName:Desktop:" of application "Image Events", embedded profile:profile "Thunderbolt Display" of image "My Image.png" of application "Image Events", file type:PNG, class:image, name:"My Image.png", resolution:{72.0, 72.0}}
        
        -- Read the image's resolution
        resolution
        --> {72.0, 72.0}
        
        -- Read the image's type
        file type
        --> PNG
        
        -- Read the name of the image's embedded profile
        name of embedded profile
        --> "Thunderbolt Display"
    end tell
end tell