好吧,我认为这将是一个简单的,但显然我错过了一些明显的东西.我的代码如下:
set fileTarget to ((path to desktop folder) & "file$") as string
if file fileTarget exists then
display dialog "it exists"
else
display dialog "it does not exist"
end if
Run Code Online (Sandbox Code Playgroud)
容易吗?不幸的是,当我运行脚本时,它返回错误
Can’t get file "OS X:Users:user:Desktop:files$".
Run Code Online (Sandbox Code Playgroud)
文件是否存在无关紧要,这与我得到的错误相同.我已经尝试了十几种不同的东西,但它仍然让我感到困惑.
我在使用AppleScript将文件夹复制到XCode项目时遇到了一些麻烦.没有Applescript我将文件夹拖入Xcode.
我使用了类似的Applescript处理程序,如下所示,使用"wrapper.library"将库复制到XCode中作为文件类型.下面我使用"wrapper.folder"尝试将文件夹复制到XCode中,但它无法正常工作.
on addFolder(fname, fpath)
tell application "Xcode"
tell project "Unity-iPhone"
set my_targets to targets
set s_target to item 1 of my_targets
set compile_phase to compile sources phase of s_target
set link_phase to get link binary with libraries phase of s_target
tell root group
set a to make new file reference with properties {full path:fpath & fname, name:fname, file type:"wrapper.folder"}
add a to link_phase
end tell
end tell
end tell
end addFolder
Run Code Online (Sandbox Code Playgroud)
有没有人对我遗失的内容或如何编写Applescript以将文件夹复制到XCode有任何想法?
我记得有一个Cocoa框架或AppleScript字典来检查计算机上的任何地方是否安装了具有特定名称的Application包.
我该怎么做呢?Cocoa,AppleScript或命令行对我都很有用.
我有一个不同长度字符串的列表,我正在循环:
set my_list to {"abc", "defg", "hi", "jklmno"}
repeat with the_item in my_list
-- get index of the_item
end repeat
Run Code Online (Sandbox Code Playgroud)
我如何在循环时找到the_item的索引?
更新:解决方案如下
假设您有Finder中所选项目的列表.假设有一些文件,文件夹,各种捆绑包,甚至包含在选择中的一些应用程序.
现在说你只想要那些(在UNIX术语中)目录的项目.也就是说,你只需要cd在终端中可以使用的物品.
您可以检查每个项目的kind属性,看它是否等于"文件夹",但这对应用程序包或其他包/包不起作用,尽管它们实际上是"文件夹"(目录)
如果项目是实际文件对象(而不是别名),则可以检查每个项目的class属性...除了并不总是有效之外,因为bundle现在是"文档文件"实例,而应用程序是"应用程序文件"实例.
如果你只有一个别名列表而不是实际的文件对象,那就更糟了,因为你无法检查class属性; 它总是只会说"别名".
我能想到的唯一解决方案是获取每个项目的POSIX路径,并查看它是否有正斜杠,或者将其路径发送到用不同语言编写的脚本,这可以检查某个目录是否是某个目录或不.
这两个想法对我来说都很疯狂.检查尾随斜杠是非常hacky和脆弱的,并将所有内容提供给不同的脚本是完全矫枉过正的.
更新: Asmus建议下面看起来确实是唯一一个很好的解决方案,因为似乎AppleScript无法自行解决这个问题:
do shell script "file -b " & filePosixPath
Run Code Online (Sandbox Code Playgroud)
这将返回文件夹,包,应用程序,软件包等的字符串"目录".
但请注意(!)对于磁盘,它返回"粘性目录".
这是一个非常好用的通用函数
on isDirectory(someItem) -- someItem is a file reference
set filePosixPath to quoted form of (POSIX path of (someItem as alias))
set fileType to (do shell script "file -b " & filePosixPath)
if fileType ends with "directory" then return true
return false
end isDirectory
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个AppleScript,它将清空Twitter for Mac的缓存,然后重新启动应用程序.我遇到的问题是确认对话框没有名称(标题栏为空)所以我迷失了如何在没有上下文的情况下定位按钮.这是我到目前为止所拥有的:
tell application "Twitter"
activate
end tell
tell application "System Events"
tell process "Twitter"
tell menu bar 1
tell menu bar item "Twitter"
tell menu "Twitter"
click menu item "Empty Cache"
end tell
end tell
end tell
end tell
end tell
tell application "System Events"
click button "Empty Cache" of window "Empty Cache?"
end tell
tell application "Twitter"
quit
end tell
tell application "Twitter"
activate
end tell
Run Code Online (Sandbox Code Playgroud) 当此曲目是收音机时,如何在iTunes中获取当前曲目的歌曲名称?
我的意思是出现在收音机名称正下方的字符串:)

在下面查询它的名字给了我radio(Trance Channel - DIGGITALLY IMPORTED - we can't define it!)的名字但不是歌曲的名字
tell application "iTunes"
set thisTrack to current track
set trackName to the name of thisTrack
set trackTime to thisTrack's time
end tell
Run Code Online (Sandbox Code Playgroud)
这是预期的,因为我的库中的信息是:
但有没有办法专门处理这些流媒体曲目?并像第一张图片中的iTunes一样正确获取他们的信息?我知道当前的音轨是一个收音机,因为它的时间将是,missing value而不是形式,MM:SS如果这有点帮助.
这可能吗?
我试图制作一个AppleScript,它应该从Finder读取当前目录并在其上运行shell命令.如果我在Finder中导航到所需的文件夹并从AppleScript编辑器运行脚本它可以工作,但是当我保存脚本并将其拖到Finder工具栏时,currentDir被设置为脚本文件的文件夹(我的用户目录).这是我的脚本:
tell application "Finder"
set currentDir to POSIX path of ((container of (path to me)) as text)
end tell
tell application "Terminal"
do script "cd " & currentDir
do script "<operation goes here>"
end tell
Run Code Online (Sandbox Code Playgroud)
使用工具栏快捷方式时,如何激活目录?第二,有没有办法在后台运行shell命令,而无需打开(显示)终端窗口?
以下工作在iTerm 2中打开两个选项卡.
我似乎无法弄清楚如何使用拆分窗格来改变它.
我试过应用我在几个论坛上看到的东西,但它永远不会奏效.有人能指出我正确的方向吗?
osascript <<-eof
tell application "iterm"
set myterm to (make new terminal)
tell myterm
launch session "Default session"
tell the last session
set name to "Server"
write text "cd $projectsFolder"
end tell
launch session "Default session"
tell the last session
set name to "Console"
write text "cd $projectsFolder"
end tell
end tell
end tell
eof
Run Code Online (Sandbox Code Playgroud) 我正在尝试将一些旧的Applescript移植到新的JavaScript语法中.
事情似乎非常直接,所以:
tell application "System Events" to keystroke "t" using command down
Run Code Online (Sandbox Code Playgroud)
成为:
System = Application('System Events');
System.keystroke("t", {using: "command down"})
Run Code Online (Sandbox Code Playgroud)
但是我不能为我的生活找出如何列出特定位置的文件.在AppleScript中,要返回目录中的文件列表/usr,您可以:
tell application "System Events" to set fileList to name of items in folder "/usr"
-- > {"bin", "include", "lib", "libexec", "local", "sbin", "share", "standalone", "X11"}
Run Code Online (Sandbox Code Playgroud)
但是我不能为我的生活弄清楚如何在Javascript中做到这一点.
System = Application('System Events')
myPath = Path("/usr")
fileList = System.items(myPath)
-- > message not understood
fileList = System.folder(myPath)
-- > message not understood
fileList = System.diskItems(myPath)
-- > []
fileList …Run Code Online (Sandbox Code Playgroud) javascript applescript automation osx-yosemite javascript-automation
applescript ×10
macos ×3
automation ×1
cocoa ×1
file ×1
finder ×1
if-statement ×1
iphone ×1
iterm ×1
itunes ×1
javascript ×1
list ×1
loops ×1
osascript ×1
osx-yosemite ×1
terminal ×1
twitter ×1
xcode ×1