创建的AppleScript和Automator的图像标注工具 [英] Create an image annotation tool with AppleScript and Automator
问题描述
在Mac上,它是可以使用的AppleScript / Automator的显示背景图像的preVIEW的Automator的应用程序运行时?
我有数百个图像到我要添加元数据,以便它们可以在网站上进行显示。我的计划是创建一个 *元
具有相同的名称作为原始图像文件,使PHP脚本可以在它生成的同时在元数据读取的URL的形象。
我已经创建了一个AppleScript文件(见下文),我已经嵌入的Automator应用程序。当你把一个选择上的应用程序文件,它首先说明你的图像,然后显示3对话框,在这里你可以输入所需的数据。
的问题是,虽然qlmanage preVIEW窗口是打开的的AppleScript被阻止。在您可以输入所需的数据,需要关闭该窗口,这样你就可以再也看不到图像。
有没有办法给qlmanage进程发送到后台,这样当图像打开对话窗口会出现?
或许已经存在于Mac OS的免费工具已经可以让你做什么,我希望做的事。
告诉应用程序发现者
设置the_selection到选择
告诉结束设置为FILE_TYPES {JPG,PNG,GIF,MP4}
设置版权为2015年©公司名称
设置签名签名从1 II重复到the_selection的计数 集合{posix_path,FILE_PATH,FILE_NAME,file_ext}以splitPath(the_selection项目II) 如果FILE_TYPES包含file_ext然后
设置meta_path为FILE_PATH&安培; FILE_NAME&安培; .META
告诉应用程序发现者
如果不是(存在文件(meta_path)),然后
做shell脚本qlmanage -s -t 640&放大器; posix_path 集alt_text文本返回的(显示对话框ALT默认回答FILE_NAME)
设置著作权的返回的文本(显示对话框中的©默认回答版权)
集签名文本返回(显示对话框中的签名默认答案签字) 设置meta_text为ALT&放大器; alt_text&安培;返回&安培; 版权和安培;版权&功放;返回&安培; 签名&放大器;签名 设置meta_file以打开具有写权限访问meta_path
写meta_text到meta_file
紧邻meta_file 万一
告诉结束
万一
重复结束在splitPath(selected_item)
告诉应用程序系统事件
集posix_path到的POSIX路径(如selected_item化名)
设置posix_path为posix_path的报价形式
告诉结束 设置为FILE_PATH作为selected_item字符串 设置file_ext为
设置FILE_NAME为 设置文本项分隔符。
如果(计数FILE_PATH的文本项)GT; 1,则
设置file_ext为FILE_PATH的最后文本项
FILE_PATH设置为字符串(通过FILE_PATH -2文本项1)
万一 设置文本项分隔符:
如果(计数FILE_PATH的文本项)GT; 1,则
设置为FILE_NAME的FILE_PATH最后文本项
FILE_PATH设置(如通过字符串的FILE_PATH -2(文本项1))及:
万一 返回{posix_path,FILE_PATH,FILE_NAME,file_ext}
结束splitPath
我写的确实大部分你在脚本中使用Editor.app什么ApplescriptOBJc(主要看是多么容易(这是))的应用p>
- 获取一个选择的图片。
- 填充文本域的信息。
- 表示各个图像。
- 写入元文件。
ApplescriptOBJc 是的AppleScript和目标之间的语法桥接语言 - C
这语言允许您访问目标-c的力量,在同一code使用它旁边的AppleScript。
我还没有添加的唯一的事情是视频文件的检查。
但是,因为这是一个例子/让你开始code,你应该能够做到这一点很容易不够。
我也通常会使用ApplescriptOBJc将文件写出来,但用你的code为熟悉
在code应该很容易跟随,更改,添加或移动UI对象,改变或更新它的逻辑。
过去code到一个新的脚本编辑器文件。然后点击保存它作为一个保持开放的应用
的code的应用程序:
- 2015年版权所有马克{}·亨特。版权所有。 使用脚本添加
使用框架基础
使用框架可可
使用框架了AppKit ---设立窗口
物业buttonWindow:类NSWindow
物业theImage:类NSImage中
物业theImageView:类NSImageView 物业altLabelField:一流的NSTextField
物业altField:一流的NSTextField
物业copyrightField:一流的NSTextField
物业sigField:一流的NSTextField 物业countLabelField:一流的NSTextField 属性the_selection:{}
物业图像列表:{} - 持有NSImage中的实例
属性imageListSplit:{} - 需要一个别名时用于文件
物业thisImage:0
物业imageCount:0 产权版权所有:2015年©公司名称
物业签名:签名
设置高度为700
设置宽度为1000
设置winRect到当前应用程序的NSMakeRect(0,0,宽度,高度)
设置buttonWindow到当前应用程序的NSWindow的页头()的initWithContentRect:winRect styleMask:7后盾:2延迟:假的
buttonWindow的setFrameAutosaveName:buttonWindow --set了按钮 设置writeButtonFrame到当前应用程序的NSMakeRect(105,(高度 - 230),100,25) - 键RECT起源,X,Y,尺寸为宽,hieght
设置writeBtn到当前应用程序的NSButton的ALLOC的initWithFrame:方法writeButtonFrame - init按钮 writeBtn的的setTitle:写入文件
设置writeBtn的bezelStyle 12 --NSRoundedBezelStyle
writeBtn的setButtonType:0 --NSMomentaryLightButton
writeBtn的setTarget:我
writeBtn的setAction命令:WriteFile的: 设置nextButtonFrame到当前应用程序的NSMakeRect(105,(高度 - 675),50,25) - 键RECT起源,X,Y,尺寸为宽,hieght
设置nextBtn到当前应用程序的NSButton的ALLOC的initWithFrame:方法nextButtonFrame - init按钮 nextBtn的的setTitle:下一步
设置nextBtn的bezelStyle 12 --NSRoundedBezelStyle
nextBtn的setButtonType:0 --NSMomentaryLightButton
nextBtn的setTarget:我
nextBtn的setAction命令:NEXTIMAGE:
-
集prevButtonFrame到当前应用程序的NSMakeRect(25,(高度 - 675),50,25)
集prevBtn到当前应用程序的NSButton的ALLOC的initWithFrame:方法prevButtonFrame prevBtn的的setTitle:preV
集prevBtn的bezelStyle 12 --NSRoundedBezelStyle
prevBtn的setButtonType:0 --NSMomentaryLightButton
prevBtn的setTarget:我
prevBtn的setAction命令:previousImage: ---
设置selectionButtonFrame到当前应用程序的NSMakeRect((宽 - 715),(高度 - 690),150,25)
设置selectionBtn到当前应用程序的NSButton的ALLOC的initWithFrame:方法selectionButtonFrame selectionBtn的的setTitle:选择新图像
设置selectionBtn的bezelStyle 12 --NSRoundedBezelStyle
selectionBtn的setButtonType:0 --NSMomentaryLightButton
selectionBtn的setTarget:我
selectionBtn的setAction命令:finderSelection:
- 设置terminatButtonFrame到当前应用程序的NSMakeRect((宽 - 90),(高度 - 690),75,25)
设置terminateBtn到当前应用程序的NSButton的ALLOC的initWithFrame:方法terminatButtonFrame terminateBtn的的setTitle:退出
设置terminateBtn的bezelStyle 12 --NSRoundedBezelStyle
terminateBtn的setButtonType:0 --NSMomentaryLightButton
terminateBtn的setTarget:我
terminateBtn的setAction命令:terminateMe
- - 添加按钮到窗口 buttonWindow的内容查看的addSubview:nextBtn
buttonWindow的内容查看的addSubview:prevBtn
buttonWindow的内容查看的addSubview:selectionBtn
buttonWindow的内容查看的addSubview:terminateBtn
buttonWindow的内容查看的addSubview:writeBtn - - 设置图像视图 集imageViewFrame到当前应用程序的NSMakeRect(300,(高度 - 660),640,640)--origin,X,Y,尺寸宽度,hieght
设置theImageView到当前应用程序的NSImageView的页头()的initWithFrame:方法imageViewFrame
theImageView的setImageFrameStyle:1 - 增加图像视图窗口
buttonWindow的内容查看的addSubview:theImageView
- 激活窗口
buttonWindow的makeKeyAndOrderFront:buttonWindow ---集ALT标签 设置altLabelFrame到当前应用程序的NSMakeRect(25,(高度 - 60),100,25)--origin,X,Y,尺寸宽度,hieght
设置altLabelField当前应用程序的NSTextField的页头()的initWithFrame:方法altLabelFrame
altLabelField的setStringValue:ALT
altLabelField的setBezeled:假的
altLabelField的setDrawsBackground:假的
altLabelField的setEditable:假的
altLabelField的setSelectable:假的 - 设置文本框ALT 设置altFieldFrame到当前应用程序的NSMakeRect(25,(高度 - 80),240,25)--origin,X,Y,尺寸宽度,hiegh
设置altField当前应用程序的NSTextField的页头()的initWithFrame:方法altFieldFrame ---
---集版权标签 集copyrightLabelFrame到当前应用程序的NSMakeRect(25,(高度 - 110),100,25)--origin,X,Y,尺寸宽度,hieght
设置copyrightLabelField当前应用程序的NSTextField的页头()的initWithFrame:方法copyrightLabelFrame copyrightLabelField的setStringValue:©版权所
copyrightLabelField的setBezeled:假的
copyrightLabelField的setDrawsBackground:假的
copyrightLabelField的setEditable:假的
copyrightLabelField的setSelectable:假的
- 建立版权文本框 集copyrightFieldFrame到当前应用程序的NSMakeRect(25,(高度 - 130),240,25)--origin,X,Y,尺寸宽度,hieght
设置copyrightField当前应用程序的NSTextField的页头()的initWithFrame:方法copyrightFieldFrame
---集签名标签 设置sigLabelFrame到当前应用程序的NSMakeRect(25,(高度 - 160),100,25)--origin,X,Y,尺寸宽度,hieght
设置sigLabelField当前应用程序的NSTextField的页头()的initWithFrame:方法sigLabelFrame sigLabelField的setStringValue:签名
sigLabelField的setBezeled:假的
sigLabelField的setDrawsBackground:假的
sigLabelField的setEditable:假的
sigLabelField的setSelectable:假的
sigLabelField的setDelegate:我
- 建立SIG文本框 设置sigFieldFrame到当前应用程序的NSMakeRect(25,(高度 - 180),240,25)--origin,X,Y,尺寸宽度,hieght
设置sigField当前应用程序的NSTextField的页头()的initWithFrame:方法sigFieldFrame ---集图像计数标签 设置countLabelFrame到当前应用程序的NSMakeRect(500,(高度 - 25),100,25)--origin,X,Y,尺寸宽度,hieght
设置countLabelField当前应用程序的NSTextField的页头()的initWithFrame:方法countLabelFrame
countLabelField的setStringValue:0
countLabelField的setBezeled:假的
countLabelField的setDrawsBackground:假的
countLabelField的setEditable:假的
countLabelField的setSelectable:假的
-
buttonWindow的内容查看的addSubview:altLabelField
buttonWindow的内容查看的addSubview:altField buttonWindow的内容查看的addSubview:copyrightLabelField
buttonWindow的内容查看的addSubview:copyrightField buttonWindow的内容查看的addSubview:sigLabelField
buttonWindow的内容查看的addSubview:sigField buttonWindow的内容查看的addSubview:countLabelField
--- 我finderSelection:(缺失值)
---
在NEXTIMAGE:发件人
buttonWindow的makeFirstResponder:(缺失值)
如果thisImage不大于imageCount更大且thisImage不等于imageCount然后 设置thisImage为thisImage + 1 theImageView的setImage:(图像列表项目thisImage) 万一
setUpTextFieldsStrings()
结束NEXTIMAGE: 在previousImage:发件人
buttonWindow的makeFirstResponder:(缺失值)
如果thisImage小于1或thisImage不等于1,则
thisImage设置为thisImage - 1 theImageView的setImage:(图像列表项目thisImage)
万一
setUpTextFieldsStrings()
结束previousImage: 在setUpTextFieldsStrings() 告诉应用程序发现者,以FILE_NAME设置为((imageListSplit项目thisImage)为化名)显示的名称
设置altField的stringValue的到file_name
设置copyrightField的stringValue的版权
设置sigField的stringValue的签字
设置countLabelField的stringValue的到(thisImage&安培;中及(imageListSplit计数)作为字符串)
结束setUpTextFieldsStrings 在WriteFile的:发件人
buttonWindow的makeFirstResponder:(缺失值)
集合{posix_path,FILE_PATH,FILE_NAME,file_ext}以splitPath(项目imageListSplit的thisImage)
设置meta_path为FILE_PATH&安培; FILE_NAME&安培; .META
告诉应用程序发现者
如果不是(存在文件(meta_path)),然后 设置alt_text为altField的stringValue的
设置copyrightText为copyrightField的stringValue的
设置signatureText为sigField的stringValue的 设置meta_text为ALT&放大器; alt_text&安培;返回&安培; 版权和安培; copyrightText&安培;返回&安培; 签名&放大器; signatureText 设置meta_file以打开具有写权限访问meta_path
写meta_text到meta_file
紧邻meta_file 万一
告诉结束
结束WriteFile的: 在finderSelection:发件人
buttonWindow的makeFirstResponder:(缺失值)
集the_selection到{}
集图像列表为{}
集imageListSplit到{} 设置imageCount 0 设置thisImage 0 利用应用程序发现者条款
集the_selection到(选择带有提示的文件请选择图片:与多选题不隐身)
结束使用条款从 与我重复从1到the_selection项目数 this_item设置为((项目the_selection作为别名我POSIX路径)) 设置工作区当前应用程序的NSWorkspace的sharedWorkspace
集类型(工作区的typeOfFile:this_item |错误|:(缺失值)) 如果(工作区的型:conformsToType:public.image),那么
图像列表的设置结束(当前应用程序的NSImage中的页头(的)initWithContentsOfFile:this_item)
imageListSplit的设置结束项目我the_selection的
万一 重复结束 如果图像列表不是{}然后
设置imageCount计算图像列表中
theImageView的setImage:(ImageList中的第1项) 设置thisImage 1
我setUpTextFieldsStrings()
万一 结束finderSelection:
在terminateMe() 告诉我要退出
结束terminateMe
在splitPath(selected_item) 告诉应用程序系统事件
集posix_path到的POSIX路径(如selected_item化名)
设置posix_path为posix_path的报价形式
告诉结束 设置为FILE_PATH作为selected_item字符串 设置file_ext为
设置FILE_NAME为 设置文本项分隔符。
如果(计数FILE_PATH的文本项)GT; 1,则
设置file_ext为FILE_PATH的最后文本项
FILE_PATH设置为字符串(通过FILE_PATH -2文本项1)
万一 设置文本项分隔符:
如果(计数FILE_PATH的文本项)GT; 1,则
设置为FILE_NAME的FILE_PATH最后文本项
FILE_PATH设置(如通过字符串的FILE_PATH -2(文本项1))及:
万一 返回{posix_path,FILE_PATH,FILE_NAME,file_ext}
结束splitPath
运行应用程序:
保存后,可以将其作为一个普通的应用程序。
您也可以从脚本编辑器中运行,但必须用<大骨节病> ALT 骨节病> +运行按钮,<大骨节病> ALT 骨节病> + <大骨节病>研究骨节病>或使用运行它菜单脚本 - > 运行应用程序
On Mac, is it possible to use AppleScript/Automator to show a preview of an image in the background, while the Automator app is running?
I have hundreds of images to which I want to add meta data so that they can be displayed on a web site. My plan is to create a *.meta
file with the same name as the original image, so that a PHP script can read in the meta data at the same time that it generates the URL for the image.
I have created an AppleScript file (see below), which I have embedded in an Automator app. When you drop a selection of files on the app, it first shows you the image, and then shows 3 dialogs where you can enter the required data.
The problem is that the AppleScript is blocked while the qlmanage preview window is open. Before you can enter the required data, you need to close the window, so you can no longer see the image.
Is there a way to send the qlmanage process into the background so that the dialog windows can appear while the image is open?
Or perhaps there is already a free tool for Mac OS that already allows you to do exactly what I hope to do.
tell application "Finder"
set the_selection to the selection
end tell
set file_types to {"jpg", "png", "gif", "mp4"}
set copyright to "© 2015 CompanyName"
set signature to "Signature"
repeat with ii from 1 to the count of the_selection
set {posix_path, file_path, file_name, file_ext} to splitPath(item ii of the_selection)
if file_types contains file_ext then
set meta_path to file_path & file_name & ".meta"
tell application "Finder"
if not (exists file (meta_path)) then
do shell script "qlmanage -t -s 640 " & posix_path
set alt_text to the text returned of (display dialog "alt" default answer file_name)
set copyright to the text returned of (display dialog "©" default answer copyright)
set signature to the text returned of (display dialog "signature" default answer signature)
set meta_text to "alt " & alt_text & return & "copyright " & copyright & return & "signature " & signature
set meta_file to open for access meta_path with write permission
write meta_text to meta_file
close access meta_file
end if
end tell
end if
end repeat
on splitPath(selected_item)
tell application "System Events"
set posix_path to POSIX path of (selected_item as alias)
set posix_path to quoted form of posix_path
end tell
set file_path to selected_item as string
set file_ext to ""
set file_name to ""
set text item delimiters to "."
if (count text items of file_path) > 1 then
set file_ext to last text item of file_path
set file_path to (text items 1 through -2 of file_path) as string
end if
set text item delimiters to ":"
if (count text items of file_path) > 1 then
set file_name to last text item of file_path
set file_path to ((text items 1 through -2 of file_path) as string) & ":"
end if
return {posix_path, file_path, file_name, file_ext}
end splitPath
I wrote an Application that does most of what you do using ApplescriptOBJc in Script Editor.app ( mainly to see how easy it was ( It was ))
- Gets a selection of images.
- Populates text fields with info.
- shows each image.
- writes to a meta file.
ApplescriptOBJc is the syntax bridging language between Applescript and Objective - c.
This language allows you to access the power of Objective -c and use it alongside Applescript in the same code.
The only thing I have not added is a check for video files.
But as this is a example/get you started code you should be able to do that easily enough.
I also would normally use ApplescriptOBJc to write the files out but used your code for familiarity
The code should be easy enough to follow, change , add or move UI objects and also change or update its logic.
Past the code into a new Script Editor document. Then Save it as a stay open application.
The Code for the App:
-- Copyright 2015 {Mark Hunte}. All rights reserved.
use scripting additions
use framework "Foundation"
use framework "cocoa"
use framework "AppKit"
--- set up window
property buttonWindow : class "NSWindow"
property theImage : class "NSImage"
property theImageView : class "NSImageView"
property altLabelField : class "NSTextField"
property altField : class "NSTextField"
property copyrightField : class "NSTextField"
property sigField : class "NSTextField"
property countLabelField : class "NSTextField"
property the_selection : {}
property imageList : {} -- holds NSImage instances
property imageListSplit : {} -- to use for file when needing an alias
property thisImage : 0
property imageCount : 0
property copyright : "© 2015 CompanyName"
property signature : "Signature"
set height to 700
set width to 1000
set winRect to current application's NSMakeRect(0, 0, width, height)
set buttonWindow to current application's NSWindow's alloc()'s initWithContentRect:winRect styleMask:7 backing:2 defer:false
buttonWindow's setFrameAutosaveName:"buttonWindow"
--set up buttons
set writeButtonFrame to current application's NSMakeRect(105, (height - 230), 100, 25) -- button rect origin ,x,y ,size width,hieght
set writeBtn to current application's NSButton's alloc's initWithFrame:writeButtonFrame -- init button
writeBtn's setTitle:"write file"
set writeBtn's bezelStyle to 12 --NSRoundedBezelStyle
writeBtn's setButtonType:0 --NSMomentaryLightButton
writeBtn's setTarget:me
writeBtn's setAction:"writeFile:"
set nextButtonFrame to current application's NSMakeRect(105, (height - 675), 50, 25) -- button rect origin ,x,y ,size width,hieght
set nextBtn to current application's NSButton's alloc's initWithFrame:nextButtonFrame -- init button
nextBtn's setTitle:"Next"
set nextBtn's bezelStyle to 12 --NSRoundedBezelStyle
nextBtn's setButtonType:0 --NSMomentaryLightButton
nextBtn's setTarget:me
nextBtn's setAction:"nextImage:"
--
set prevButtonFrame to current application's NSMakeRect(25, (height - 675), 50, 25)
set prevBtn to current application's NSButton's alloc's initWithFrame:prevButtonFrame
prevBtn's setTitle:"Prev"
set prevBtn's bezelStyle to 12 --NSRoundedBezelStyle
prevBtn's setButtonType:0 --NSMomentaryLightButton
prevBtn's setTarget:me
prevBtn's setAction:"previousImage:"
---
set selectionButtonFrame to current application's NSMakeRect((width - 715), (height - 690), 150, 25)
set selectionBtn to current application's NSButton's alloc's initWithFrame:selectionButtonFrame
selectionBtn's setTitle:"Select new Images"
set selectionBtn's bezelStyle to 12 --NSRoundedBezelStyle
selectionBtn's setButtonType:0 --NSMomentaryLightButton
selectionBtn's setTarget:me
selectionBtn's setAction:"finderSelection:"
--
set terminatButtonFrame to current application's NSMakeRect((width - 90), (height - 690), 75, 25)
set terminateBtn to current application's NSButton's alloc's initWithFrame:terminatButtonFrame
terminateBtn's setTitle:"Quit"
set terminateBtn's bezelStyle to 12 --NSRoundedBezelStyle
terminateBtn's setButtonType:0 --NSMomentaryLightButton
terminateBtn's setTarget:me
terminateBtn's setAction:"terminateMe"
--
-- add buttons to the window
buttonWindow's contentView's addSubview:nextBtn
buttonWindow's contentView's addSubview:prevBtn
buttonWindow's contentView's addSubview:selectionBtn
buttonWindow's contentView's addSubview:terminateBtn
buttonWindow's contentView's addSubview:writeBtn
--
-- set up image view
set imageViewFrame to current application's NSMakeRect(300, (height - 660), 640, 640) --origin ,x,y ,size width,hieght
set theImageView to current application's NSImageView's alloc()'s initWithFrame:imageViewFrame
theImageView's setImageFrameStyle:1
-- add image view to the window
buttonWindow's contentView's addSubview:theImageView
-- activate the window
buttonWindow's makeKeyAndOrderFront:buttonWindow
--- set alt label
set altLabelFrame to current application's NSMakeRect(25, (height - 60), 100, 25) --origin ,x,y ,size width,hieght
set altLabelField to current application's NSTextField's alloc()'s initWithFrame:altLabelFrame
altLabelField's setStringValue:"alt"
altLabelField's setBezeled:false
altLabelField's setDrawsBackground:false
altLabelField's setEditable:false
altLabelField's setSelectable:false
-- set up alt textField
set altFieldFrame to current application's NSMakeRect(25, (height - 80), 240, 25) --origin ,x,y ,size width,hiegh
set altField to current application's NSTextField's alloc()'s initWithFrame:altFieldFrame
---
--- set copyright label
set copyrightLabelFrame to current application's NSMakeRect(25, (height - 110), 100, 25) --origin ,x,y ,size width,hieght
set copyrightLabelField to current application's NSTextField's alloc()'s initWithFrame:copyrightLabelFrame
copyrightLabelField's setStringValue:"©opyright"
copyrightLabelField's setBezeled:false
copyrightLabelField's setDrawsBackground:false
copyrightLabelField's setEditable:false
copyrightLabelField's setSelectable:false
-- set up copyright textFields
set copyrightFieldFrame to current application's NSMakeRect(25, (height - 130), 240, 25) --origin ,x,y ,size width,hieght
set copyrightField to current application's NSTextField's alloc()'s initWithFrame:copyrightFieldFrame
--- set sig label
set sigLabelFrame to current application's NSMakeRect(25, (height - 160), 100, 25) --origin ,x,y ,size width,hieght
set sigLabelField to current application's NSTextField's alloc()'s initWithFrame:sigLabelFrame
sigLabelField's setStringValue:"signature"
sigLabelField's setBezeled:false
sigLabelField's setDrawsBackground:false
sigLabelField's setEditable:false
sigLabelField's setSelectable:false
sigLabelField's setDelegate:me
-- set up sig textFields
set sigFieldFrame to current application's NSMakeRect(25, (height - 180), 240, 25) --origin ,x,y ,size width,hieght
set sigField to current application's NSTextField's alloc()'s initWithFrame:sigFieldFrame
--- set image count label
set countLabelFrame to current application's NSMakeRect(500, (height - 25), 100, 25) --origin ,x,y ,size width,hieght
set countLabelField to current application's NSTextField's alloc()'s initWithFrame:countLabelFrame
countLabelField's setStringValue:"0"
countLabelField's setBezeled:false
countLabelField's setDrawsBackground:false
countLabelField's setEditable:false
countLabelField's setSelectable:false
--
buttonWindow's contentView's addSubview:altLabelField
buttonWindow's contentView's addSubview:altField
buttonWindow's contentView's addSubview:copyrightLabelField
buttonWindow's contentView's addSubview:copyrightField
buttonWindow's contentView's addSubview:sigLabelField
buttonWindow's contentView's addSubview:sigField
buttonWindow's contentView's addSubview:countLabelField
---
my finderSelection:(missing value)
---
on nextImage:sender
buttonWindow's makeFirstResponder:(missing value)
if thisImage is not greater than imageCount and thisImage is not equal to imageCount then
set thisImage to thisImage + 1
theImageView's setImage:(item thisImage of imageList)
end if
setUpTextFieldsStrings()
end nextImage:
on previousImage:sender
buttonWindow's makeFirstResponder:(missing value)
if thisImage is less than 1 or thisImage is not equal to 1 then
set thisImage to thisImage - 1
theImageView's setImage:(item thisImage of imageList)
end if
setUpTextFieldsStrings()
end previousImage:
on setUpTextFieldsStrings()
tell application "Finder" to set file_name to displayed name of ((item thisImage of imageListSplit) as alias)
set altField's stringValue to file_name
set copyrightField's stringValue to copyright
set sigField's stringValue to signature
set countLabelField's stringValue to (thisImage & " of " & (count of imageListSplit) as string)
end setUpTextFieldsStrings
on writeFile:sender
buttonWindow's makeFirstResponder:(missing value)
set {posix_path, file_path, file_name, file_ext} to splitPath(item thisImage of imageListSplit)
set meta_path to file_path & file_name & ".meta"
tell application "Finder"
if not (exists file (meta_path)) then
set alt_text to altField's stringValue
set copyrightText to copyrightField's stringValue
set signatureText to sigField's stringValue
set meta_text to "alt " & alt_text & return & "copyright " & copyrightText & return & "signature " & signatureText
set meta_file to open for access meta_path with write permission
write meta_text to meta_file
close access meta_file
end if
end tell
end writeFile:
on finderSelection:sender
buttonWindow's makeFirstResponder:(missing value)
set the_selection to {}
set imageList to {}
set imageListSplit to {}
set imageCount to 0
set thisImage to 0
using terms from application "Finder"
set the_selection to (choose file with prompt "Please select images:" with multiple selections allowed without invisibles)
end using terms from
repeat with i from 1 to number of items in the_selection
set this_item to (POSIX path of (item i of the_selection as alias))
set workSpace to current application's NSWorkspace's sharedWorkspace
set type to (workSpace's typeOfFile:this_item |error|:(missing value))
if (workSpace's type:type conformsToType:"public.image") then
set end of imageList to (current application's NSImage's alloc()'s initWithContentsOfFile:this_item)
set end of imageListSplit to item i of the_selection
end if
end repeat
if imageList is not {} then
set imageCount to count of imageList
theImageView's setImage:(item 1 of imageList)
set thisImage to 1
my setUpTextFieldsStrings()
end if
end finderSelection:
on terminateMe()
tell me to quit
end terminateMe
on splitPath(selected_item)
tell application "System Events"
set posix_path to POSIX path of (selected_item as alias)
set posix_path to quoted form of posix_path
end tell
set file_path to selected_item as string
set file_ext to ""
set file_name to ""
set text item delimiters to "."
if (count text items of file_path) > 1 then
set file_ext to last text item of file_path
set file_path to (text items 1 through -2 of file_path) as string
end if
set text item delimiters to ":"
if (count text items of file_path) > 1 then
set file_name to last text item of file_path
set file_path to ((text items 1 through -2 of file_path) as string) & ":"
end if
return {posix_path, file_path, file_name, file_ext}
end splitPath
Running the App:
Once saved you run it as a normal application.
You can also run it from within Script Editor but must Run it using either alt + the run button, alt + R or use the menu Script->Run Application.
这篇关于创建的AppleScript和Automator的图像标注工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!