0

I am writing a simple script to search application from iTunes store. The app does the following:

-- Read the application from a user input (text field in a dialog box)

-- Take the app name in a variable and keystroke the app name in the search text field in iTunes (Right Top Corner).

-- Press enter (keystroke return) .

The problem I am struggling is:

When the user inputs a Japanese text as a app name, I need to detect that it is a Japanese text and need to change the keyboard input type to JP before keystroke to the search field.

And sometimes the app name contains both EN and JP character set.

Can someone help me how to detect character encoding of every character with AppleScript?

Thanks and Best Regards

Rahman

4

1 回答 1

2

您可能只使用itunesURL:

itunes://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?term=漢字
text returned of (display dialog "" default answer "")
do shell script "u=itunes://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa
q=$(printf %s " & quoted form of result & " | xxd -p | tr -d '\\n' | sed 's/../%&/g')
open $u/search?term=$q"

您还可以使用剪贴板插入文本:

try
    set old to the clipboard as record
end try
set the clipboard to "漢字"
tell application "System Events"
    keystroke "v" using command down
end tell
delay 0.1
try
    set the clipboard to old
end try

如果剪贴板为空,尝试获取它会导致错误。the clipboard是like the clipboard as textthe clipboard as record还包括其他类型。模拟击键通常比单击菜单栏项更快,并且单击菜单栏项在全屏窗口或应用程序没有菜单栏时不起作用。如果没有延迟,set the clipboard to old有时会在粘贴文本之前运行。

或者在这种情况下,您可以使用 UI 脚本:

tell application "iTunes"
    reopen
    activate
end tell
tell application "System Events" to tell process "iTunes"
    tell text field 1 of (get value of attribute "AXMainWindow")
        set value to "漢字"
        set selected to true
    end tell
    keystroke return
end tell
于 2013-08-19T15:25:45.477 回答