Cách tạo extension cho PopClip thì rất linh hoạt. Hướng dẫn có trong 2 bài viết bằng tiếng Anh mình dẫn trên kia. Mình chỉ xin tóm tắt lại cách làm cái extension đơn giản của mình.
Bước 1: Tạo một thư mục có tên là tên của extension (VietnamDict)
Bước 2: Chuẩn bị 3 file cho thư mục
(1) Config.plist : file lưu thông tin config của extention. Có 3 trường quan trọng là
+ AppleScript File: Tên file script chính của extension
+ Image File: Tên file ảnh dùng làm icon của extension trong PopClip
+ Extension Name: Tên của extension cũng chính là tên thư mục
Mã nguồn HTML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Actions</key>
<array>
<dict>
<key>AppleScript File</key>
<string>tudien.applescript</string>
<key>Image File</key>
<string>tudien.png</string>
<key>Title</key>
<string>Vietnam Dictionaries</string>
</dict>
</array>
<key>Extension Description</key>
<string>Search the selected word in Vietnam Dictionaries application</string>
<key>Extension Identifier</key>
<string>popclip.extension.vietnamdict</string>
<key>Extension Name</key>
<string>VietnamDict</string>
<key>Required Software Version</key>
<integer>701</integer>
</dict>
</plist>
(2) tudien.applescript: mình dùng applescript để tạo extension (có thể tạo bằng ngôn ngữ khác)
<div class="bbCodeBlock bbCodePHP">
<div class="type">PHP:</div>
<div class="code"><code>
-- Process seletected string
set oldWord to "{popclip text}" -- từ đã chọn
set theCmd to ("echo " & quoted form of oldWord & " | perl -pe " & quoted form of "s/[- ]//g" as string) -- dùng perl (hoặc sed, awk, ...) để chỉnh lại từ đã& nbsp;chọn theo nhu cầu (ví dụ như mình muốn&nbs p;bỏ dấu cách trắng và dấu gạch ngang)
set newWord to do shell script theCmd
set the clipboard to newWord&n bsp;-- copy từ đã chọn vào&nbs p;clipboard
tell application "Vietnam Dictionaries" to activate -- gọi đến ứng dụng từ điển
repeat
if application "Vietnam Dictionaries" is running then exit repeat -- chờ đến khi ứng dụng& nbsp;khởi động xong
delay 0.5
end repeat
delay 0.5
tell application "System Events"
tell process "Vietnam Dictionaries" -- focus vào ô để nhập&nbs p;từ trong ứng dụng từ điển
pe rform action "AXRaise" of window 1
se t value of attribute "AXFocused" of UI element 4 of front& nbsp;window to true
end tell
keystroke "a" using command down -- thực hiện Command+A để select toàn bộ  ;ô
delay 0.1
keystroke (ASCII character 8) -- thực hiện Delete để xó a từ đã có
delay 0.1
keystroke "v" using command down -- thực hiện Command+V để paste từ đã c họn
delay 0.1
keystroke return -- thực hiện bấm Enter (hay Return) để tra từ
end tell
</code></div>
</div>Chú ý
- Dựa vào thao tác trong từ điển mình dùng để code.
- Để focus vào ô nhập dữ liệu thì phải xác định được UI element bao nhiêu (trong từ điển mình dùng là 4). Bạn có thể dùng Accessibility Inspector của XCode để tìm hiểu (Link tut
Accessibility Inspector - All this)
(3) tudien.png: file icon của extension hiển thị trong PopClip với kích thước chính xác là 256x256 và thuộc tính transparent đen trắng.
Bước 3: Thêm vào đằng sau tên thư mục đuôi .popclipext. Khi đó thư mục sẽ tự động đổi thành extenstion của PopClip. Done [IMG]styles/default/xenforo/clear.png[/IMG]
Trên đây là một số kinh nghiệm của mình. Chúc bạn sớm tạo được extension cho riêng mình [IMG]styles/default/xenforo/clear.png[/IMG]
Để tối ưu hóa hoạt động sản xuất và kinh doanh, nhiều doanh nghiệp lựa chọn thuê đất khu công nghiệp (KCN) thay vì tự xây dựng nhà xưởng riêng. KCN mang đến nhiều lợi ích như hạ tầng hoàn thiện, dịch...
Hướng dẫn toàn diện cho doanh...