Image 用于显示图像属性的applescript代码

Image 用于显示图像属性的applescript代码,image,properties,applescript,Image,Properties,Applescript,我不熟悉applescript。我想用applescript开发一个应用程序 下面是我的代码。在运行它时,它会显示无法生成alias的finder。请帮帮我 property script_name : "image Tracker" property script_description : "image property data finder" --set the_folder to (choose folder with prompt "Select the folder for ge

我不熟悉applescript。我想用applescript开发一个应用程序

下面是我的代码。在运行它时,它会显示无法生成alias的finder。请帮帮我

property script_name : "image Tracker"
property script_description : "image property data finder"

--set the_folder to (choose folder with prompt "Select the folder for get the image property:") as Unicode text

--set the_folder to quoted form of POSIX path of (choose folder with prompt "Select the folder for get the image property:")

set the_folder to (choose folder)

copy {"jpg", "png", "eps", "ai", "tif", "psd", "gif"} to validExtentions

tell application "Finder" to set fPaths to file the_folder
repeat with thisFilePath in fPaths
    if name extension of thisFilePath is in validExtensions then
        try
            tell application "Image Events"
                -- start the Image Events application
                launch
                -- open the image file
                set this_image to open this_file
                -- extract the properties record
                set the props_rec to the properties of this_image
                -- purge the open image data
                close this_image
                -- extract the property values from the record
                set the image_info to ""
                set the image_info to the image_info & ¬
                    "Name: " & (name of props_rec) & return
                set the image_info to the image_info & ¬
                    "*********************************************" & return
                set the image_info to the image_info & ¬
                    "File: " & (path of image file of props_rec) & return
                set the image_info to the image_info & ¬
                    "File Type: " & (file type of props_rec) & return
                set the image_info to the image_info & ¬
                    "Res: " & item 1 of (resolution of props_rec) & return
                set the image_info to the image_info & ¬
                    "Color Space: " & (color space of props_rec) & return
                copy (dimensions of props_rec) to {x, y}
                set the image_info to the image_info & ¬
                    "Dimemsions: " & x & ", " & y
            end tell
        on error error_message
            display dialog error_message
        end try
    end if
end repeat

set myfile to open for access ("Macintosh HD:Users:varghese.pt:Desktop:") & "image_data.txt" with write permission
write image_info to myfile
close access myfile
如果有人找到了答案,请把详细情况告诉我。 提前谢谢


尼丁·约瑟夫(Nidhin Joseph)

让我先说一句:不幸的是,总的来说,AppleScript是一只挑剔的野兽,有时尝试和错误是你唯一的朋友

您的代码有几个问题-有些是明显的,有些不是:

validExtensions在copy{jpg…语句中拼写错误-您稍后使用拼写正确的名称validExtensions引用

在tell application Finder命令中,必须将文件替换为文件夹

在命令“设置此\u图像以打开此\u文件”中,您必须将此\u文件替换为文本形式的文件路径。注意:插入括号和文本是至关重要的,否则文件将由Finder打开,从而在Preview.app中打开-不要问我为什么会这样

我还建议将write to file命令中的硬编码路径替换为text&image_data.txt形式的桌面路径

如果我们把所有这些放在一起,我们会得到:

将{jpg、png、eps、ai、tif、psd、gif}复制到ValidExtrade 将_文件夹设置为选择文件夹 告诉应用程序查找程序使用\u文件夹中的此文件路径重复 如果此文件路径的扩展名有效,则 尝试 告诉应用程序映像事件 启动映像事件应用程序 发射 打开图像文件 设置此_映像以打开此文件路径 将此图像设置为以文本形式打开此文件路径 提取属性记录 将props\u rec设置为此图像的属性 清除打开的图像数据 关闭此图像 从记录中提取属性值 将图像信息设置为 将图像信息设置为图像信息& 名称:&道具记录和返回的名称 将图像信息设置为图像信息& *********************************************&返回 将图像信息设置为图像信息& 文件:&道具记录和返回的图像文件路径(&U) 将图像信息设置为图像信息& 文件类型:&道具记录和返回的文件类型 将图像信息设置为图像信息& 回复:&道具回收和返还决议第1项 将图像信息设置为图像信息& 颜色空间:道具记录和返回的颜色空间(&C) 将props_rec的尺寸复制到{x,y} 将图像信息设置为图像信息& 尺寸:&x&&y 我的dlogimage_信息 结束语 关于错误消息 显示对话框错误消息 结束尝试 如果结束 结束重复 将myfile设置为打开,以便以具有写入权限的text&image\u data.txt形式访问桌面 将图像信息写入myfile 关闭访问我的文件 最后,您可以通过从Finder上下文中的枚举文件切换到System Events上下文中的枚举来提高代码的性能:

如果用下面两行替换上面代码中的当前对应行,脚本将运行得更快。你会问为什么?我也不知道

告诉应用程序系统事件以文本形式重复alias_文件夹中的thisFilePath 将此_映像设置为打开此文件路径的获取路径
我建议您从问题中删除您的电子邮件地址;如果有答案,将在此处发布,您将收到网站本身的通知。我使用了此代码,但此错误再次出现,如文件我已准备好打开,并且在写入文件时图像信息变量中没有数据。请帮助我。我使用此应用程序:我需要获取图像的一些属性n文件夹;图像名称。将所有内容写入一个文件。就是这样。@aadhi:具体地说,是什么产生了错误,以及错误消息是什么>