为什么在AppleScript的脚本编辑器中运行,但是当保存误差应用? [英] Why does Applescript run in Script Editor, but error when saved as Application?

查看:108
本文介绍了为什么在AppleScript的脚本编辑器中运行,但是当保存误差应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的AppleScript需要检测其自身的文件名,并在雪豹以下运行正常(10.6)

My applescript needs to detect its own filename, and the following runs fine on Snow Leopard (10.6)

set my_name to name of me as string
display dialog "Name: " & my_name

它显示姓名:AppleScript的编辑器当我从AppleScript的编辑器中运行它,它会显示姓名:NewTest当我把它保存为名为NewTest应用

It displays "Name: AppleScript Editor" when I run it from AppleScript Editor, and it displays "Name: NewTest" when I save it as an application called NewTest.

当我一个Leopare(10.5)的机器上运行它,它抱怨不能使&LT名称;>成字符串类型。当我删除作为字符串部分,它运行在脚本编辑器,返回姓名:脚本编辑器,但是当保存为一个应用程序,它的错误,并说,无法获取的名字。

When I run it on a Leopare (10.5) machine, it complains "Can't make name of <> into type string." When I remove the "as string" portion, it runs under Script Editor, returning "Name: Script Editor", but when saved as an application, it errors and says, "Can't get name."

什么是不同的关于脚本编辑器运行和10.5下保存为应用程序?

What is different about running in script editor and saving as application under 10.5?

推荐答案

下面是另一个想法,虽然我还没有检查。有一件事,可能会导致问题就是命令搞定。一般来说,当你运行像我的名字一个命令的命令得到的是隐含的,所以你真的跑让我的名字。的问题是,暗示获取并非总是如此。所以有时你必须明确地说搞定。每当我有像您这样一个问题,我尝试的第一件事就是加入搞定的命令,它已经成为习惯,因为你永远不知道。注意,你可以随时使用这个词get和永远不会有这个问题。因此,请尝试更改您的命令为MY_NAME设置为(让我的名字)。我很想知道,如果修复您的问题10.5。另外请注意,一个名字已经是一个字符串,因此没有必要将结果强制为字符串。

Here's another thought although I haven't checked. One thing that can cause problems is the command "get". In general when you run a command like "name of me" the command get is implied so you're really running "get name of me". The problem is that the implied "get" is not always the case. So sometimes you have to explicitly say "get". Whenever I have a problem like yours the first thing I try is to add "get" to the command... it's become habit because you just never know. Note that you can always use the word get and never have that issue. As such, try changing your command to "set my_name to (get name of me)". I'd be interested to know if that fixes your 10.5 problem. Also note that a name is already a string so there's no need to coerce the result to a string.

编辑:
我通过我的一些旧的脚本看去。我用下面的code得到的名称。在我的笔记我的这些意见...

I looked through some of my older scripts. I used the following code to get the name. In my notes I have these comments...

- 这将让应用程序或脚本的名称没有任何文件扩展名。

-- this will get the name of the application or script without any file extension

- 这是当一个脚本,从脚本菜单中运行,而你写MYNAME设置为我的名字,因为,那么结果是AppleScript运行,而不是实际的名称使用路径完成

-- it is done using the path because when a script is run from the script menu, and you write set myName to name of me, then the result is "applescript runner" instead of the actual name

- 这也保证了,因为它出现在Finder中,你得到的名称,因为有时系统事件进程的名称是比搜索名称

-- also it assures that you're getting the name as it appears in the Finder because sometimes the system events process name is different than the Finder name

on getMyName()
    set myPath to path to me as text
    if myPath ends with ":" then
        set n to -2
    else
        set n to -1
    end if
    set AppleScript's text item delimiters to ":"
    set myName to text item n of myPath
    if (myName contains ".") then
        set AppleScript's text item delimiters to "."
        set myName to text 1 thru text item -2 of myName
    end if
    set AppleScript's text item delimiters to ""
    return myName
end getMyName

这篇关于为什么在AppleScript的脚本编辑器中运行,但是当保存误差应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆