0

メニューバーにデータを表示する画面を実行します

変数は「~/Desktop/_MyData.plist」から取得されます

すべて正常に動作しますが、_MyData.plist でデータが変更された場合

新しいデータを取得するスクリプトを作成するにはどうすればよいですか? AppleScript がファイルの変更を検出してスクリプトを実行することは期待できないと思いますが、plist データをアイドル状態にしてスクリプト全体を実行し続ける方法はありますか。

データのみを取得する部分は次のとおりです。

property theAccountNumberFromPlist : ""
property SNNumber : ""
property appName : ""
property devicesID : ""
property domainEMAIL : ""
property fullEmail : ""
property purchaseDate : ""
property thename : ""
property theList : ""

set the plistfile_path to "~/Desktop/_MyData.plist.plist"
tell application "System Events"
    set p_list to property list file (plistfile_path)
    -- read the plist data

set theAccountNumberFromPlist to value of property list item "AccountNumber" of p_list as text
set SNNumber to value of property list item "SNNUMBER" of p_list as text
set appName to value of property list item "appName" of p_list as text
set devicesID to value of property list item "devicesID" of p_list as text
set domainEMAIL to value of property list item "domainEMAIL" of p_list as text
set fullEmail to value of property list item "fullEmail" of p_list as text
set purchaseDate to value of property list item "purchaseDate" of p_list as text
set thename to value of property list item "thename" of p_list as text

終わりを告げる

スクリプト全体は次のとおりです。

  use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property StatusItem : missing value
property selectedMenu : ""
property theDisplay : ""
property defaults : class "NSUserDefaults"
property internalMenuItem : class "NSMenuItem"
property externalMenuItem : class "NSMenuItem"
property newMenu : class "NSMenu"
property theAccountNumberFromPlist : ""
property SNNumber : ""
property appName : ""
property devicesID : ""
property domainEMAIL : ""
property fullEmail : ""
property purchaseDate : ""
property thename : ""
property theList : ""




set the plistfile_path to "~/Desktop/_MyData.plist.plist"
tell application "System Events"
    set p_list to property list file (plistfile_path)
    -- read the plist data

    set theAccountNumberFromPlist to value of property list item "AccountNumber" of p_list as text
    set SNNumber to value of property list item "SNNUMBER" of p_list as text
    set appName to value of property list item "appName" of p_list as text
    set devicesID to value of property list item "devicesID" of p_list as text
    set domainEMAIL to value of property list item "domainEMAIL" of p_list as text
    set fullEmail to value of property list item "fullEmail" of p_list as text
    set purchaseDate to value of property list item "purchaseDate" of p_list as text
    set thename to value of property list item "thename" of p_list as text
end tell
if not (current application's NSThread's isMainThread()) as boolean then
    display alert "This script must be run from the main thread." buttons {"Cancel"} as critical
    error number -128
end if

on menuNeedsUpdate:(menu)

    my makeMenus()
end menuNeedsUpdate:

on makeMenus()

    newMenu's removeAllItems()

    repeat with i from 1 to number of items in someListInstances
        set this_item to item i of someListInstances
        set thisMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:this_item action:"someAction:" keyEquivalent:"")

        (newMenu's addItem:thisMenuItem)

        (thisMenuItem's setTarget:me) -- required for enabling the menu item
        if i is equal to 3 then
            (newMenu's addItem:(current application's NSMenuItem's separatorItem)) -- add a seperator
        end if
    end repeat

end makeMenus



on someAction:sender
    --MenuItem 
end someAction:

-- create an NSStatusBar
on makeStatusBar()
    set bar to current application's NSStatusBar's systemStatusBar

    set StatusItem to bar's statusItemWithLength:-1.0

    -- set up the initial NSStatusBars title
    StatusItem's setTitle:(theAccountNumberFromPlist & " " & thename & " " & fullEmail & " " & SNNumber & " " & appName)
    -- set up the initial NSMenu of the statusbar
    set newMenu to current application's NSMenu's alloc()'s initWithTitle:"Custom"

    newMenu's setDelegate:me (*


    *)

    StatusItem's setMenu:newMenu

end makeStatusBar


my makeStatusBar()
4

1 に答える 1