MAC
 Computer >> コンピューター >  >> システム >> MAC

生産性を向上させるためのMacのApplescriptの5つの使用

生産性を向上させるためのMacのApplescriptの5つの使用

Applescriptは、Appleのややあいまいなスクリプト言語ですが、初心者プログラムが利用できる強力なツールです。煩わしいタスクを処理するいくつかの巧妙なApplescriptを使用して、生産性を向上させ、ブルースを自動化することができます。

Applescriptとは何ですか?

生産性を向上させるためのMacのApplescriptの5つの使用

Applescriptは、Finder、iTunes、QuickTime、MailなどのほとんどのMacアプリケーションとインターフェイスします。 Automatorに精通している場合、Applescriptはそのアプリケーションのパワーユーザーバージョンのようなものです。

1。隠しファイルを切り替える

これをアプリケーションとして保存すると、クリック可能なトグルでFinderに隠しファイルを表示できます。

set newHiddenState to "YES"
try
    set oldHiddenState to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if oldHiddenState is in {"1", "YES"} then
        set newHiddenState to "NO"
    end if
end try
do shell script "defaults write com.apple.finder AppleShowAllFiles " & newHiddenState
do shell script "killAll Finder"

2。ファイルの名前を一括変更

このスクリプトは、ユーザーにファイル名の入力を求め、選択したファイルの名前をそのテキスト文字列と増分インデックスで自動的に変更します。 1から10までのファイルに先行ゼロを追加することもできます。

-- This code comes from https://gist.github.com/oliveratgithub/
-- Open in AppleScript Editor and save as Application
-- ------------------------------------------------------------
--this is required to break the filename into pieces (separate name and extension)
set text item delimiters to "."
tell application "Finder"
    set all_files to every item of (choose file with prompt "Choose the Files you'd like to rename:" with multiple selections allowed) as list
    display dialog "New file name:" default answer ""
    set new_name to text returned of result
    --now we start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
    --the 'index' number is of course required for the sequential renaming of our files!
    repeat with index from 1 to the count of all_files
        --using our index, we select the appropriate file from our list
        set this_file to item index of all_files
        set file_name_count to text items of (get name of this_file)
        --if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
        if index is less than 10 then
            set index_prefix to "0"
        else
            set index_prefix to "" 
        end if
        --
        --lets check if the current file from our list (based on index-number) has even any file-extension
        if number of file_name_count is 1 then
            --file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
            set file_extension to ""
        else
            --yup, we are currently processing a file that has a file-extension
            --we have to re-add the original file-extension after changing the name of the file!
            set file_extension to "." & item -1 of file_name_count
        end if
        --let's rename our file, add the sequential number from 'index' and add the file-extension to it
        set the name of this_file to new_name & index_prefix & index & file_extension as string
    end repeat
    --congratulations for successfully accomplishing the batch renaming task :)
    display alert "All done! Renamed " & index & " files with '" & new_name & "' for you. Have a great day! :)"
end tell

3。パーセンテージで画像を拡大縮小する

このスクリプトは、画像を元のサイズの50%に拡大縮小します。

-- Prompt for an image
set theImageFile to choose file of type "public.image" with prompt "Please select an image:"
 
-- Locate an output folder
set theOutputFolder to (path to desktop folder as string)
 
-- Launch Image Events
tell application "Image Events"
    launch
 
    -- Open the image
    set theImage to open theImageFile
    tell theImage
 
        -- Determine a save name for the image
        set theName to name
        set theSaveName to "smlr-" & theName
 
        -- Scale the image by 50%
        scale by factor 0.5
 
        -- Save the image to the output folder, using the save name
        save as file type in (theOutputFolder & theSaveName)
 
        -- Close the image
        close
    end tell
end tell

4。画像をピクセル幅に拡大縮小

これは、前のスクリプトの開始の多くを使用しますが、代わりにピクセル幅にスケーリングします。ユーザーに目的のピクセル幅の入力を求め、そのピクセル幅を新しいファイルの名前の先頭に追加します。

-- Prompt for an image
set theImageFile to choose file of type "public.image" with prompt "Please select an image:"
 
set dialogResult to (display dialog "Enter desired pixel width:" default answer "") try set pixelWidth to (text returned of dialogResult) as integer end try 
 
-- Locate an output folder
set theOutputFolder to (path to desktop folder as string)
 
-- Launch Image Events
tell application "Image Events"
    launch
 
    -- Open the image
    set theImage to open theImageFile
    tell theImage
 
        -- Determine a save name for the image
        set theName to name
        set theSaveName to (pixelWidth as text) & "-px-" & theName
 
        -- Scale the image to pixelWidth
        scale to size pixelWidth
 
        -- Save the image to the output folder, using the save name
        save as file type in (theOutputFolder & theSaveName)
 
        -- Close the image
        close
    end tell
end tell

5。選択した宛先にフォルダをバックアップする

この単純なスクリプトは、選択したフォルダを選択した宛先に複製するため、複雑なドラッグアンドドロップコピーの負担が少し軽減されます。

set backupTarget to (choose folder with prompt "Select a Backup Target")
set backupDestination to (choose folder with prompt "Select a Backup Destination")
tell application "Finder"
    duplicate folder backupTarget to folder backupDestination
end tell

結論

AppleScriptの詳細については、Apple独自のドキュメントをご覧ください。 MacOSXAutomation.comの方が優れています。これは、初心者にとってより使いやすいものです。


  1. Windows &Mac 向けの最高の DJ ソフトウェア

    DJ がすべての努力と機械を最大限に活用すると、パーティーは活気づきます。 DJ セットアップは高価であり、それに対処するには多くのトレーニングと教育が必要です。 1 時間のマニュアルでは、利用可能な DJ デッキを操作するのに役立たない場合があります。マシンや音楽ミキサーが無数にあるため、DJ を行うのは非常に困難な作業です。現在、DJ を行う最良の方法はコンピューターを使用することであることがよく知られています。 Windows PC でも Mac でも、仕事を遂行するために必要なすべてのツールとソフトウェアが提供されます。ステージに上がる前に、Windows および Mac 用の最高の

  2. Mac 向けのベスト バックアップ ソフトウェア 8 選

    何も持続しない永遠に;あなたのMacでさえありません。高度なセキュリティ アップデートと機能にもかかわらず、Mac はサイバー攻撃やデータ侵害の影響を受けません。 また、システムが機能しなくなる可能性がある突然の停電からシステムを保護することはできません。そのため、データ ファイルのバックアップを取っておくことをお勧めします。Mac バックアップ ソフトウェアに勝るものはありません。 この記事では、個人用および仕事用のファイルを保存するために利用できる、Mac 用の最も信頼性が高く最適なバックアップ ソフトウェアについて概説します。 ベスト 10 の Mac バックアップ ソフトウェア 1.