ぼんやりDTP

DTPに関係したりしなかったりするぼんやりとした話をなんとなく。

「OS付属の辞書、Logophile、Googleで検索する」AppleScript

Macで「OS付属の辞書、LogophileGoogleで検索する」AppleScript

アプリケーション形式で保存しての使用前提。

実行するとダイアログが出るので、それに従う。

実行時のダイアログ画像
実行時のダイアログ画像

Python

--DESCRIPTION:OS付属の辞書、Logophile、Googleで検索する.scpt

(*
作成日:2015-04-24
修正日:2017-06-21
作成環境:Mac OS X 10.7.5
*)

property name : "OS付属の辞書、Logophile、Googleで検索する.scpt"
property target_URL_g_sr : "https://www.google.co.jp/search?hl=ja&q="
property target_URL_g_tr : "https://translate.google.com/?hl=ja#auto/ja/"

--参照URL
--http://sakito.jp/mac/dictionary.html
--雑多の備忘録 - AppleScript/文字列
--http://qz.tsugumi.org/AppleScript%2F%CA%B8%BB%FA%CE%F3.html
--AppleScript for Python Programmers (Comparison Chart), by Aurelio Jargas
--http://aurelio.net/articles/applescript-vs-python.html
--MacScripter / Trim [Remove Spaces]
--http://macscripter.net/viewtopic.php?id=18519
--ASCIIコード表
--http://www9.plala.or.jp/sgwr-t/c_sub/ascii.html

on run
    --set gotValue to my getStringAtFrontMostApp()
    
    try
        set gotValue to the clipboard as Unicode text
        set gotValue to my trim(true, gotValue)
    on error
        set gotValue to ""
    end try
    
    if gotValue is "" then
        set theResult to display dialog "Please input words to search." default answer "" buttons {"Cancel", "Dictionary", "Google"} default button 2
        set gotValue to text returned of theResult
        --display dialog gotValue
        set gotButton to button returned of theResult
    else
        set theResult to display dialog "Please check words to search." default answer gotValue buttons {"Cancel", "Dictionary", "Google"} default button 2
        set gotValue to text returned of theResult
        set gotButton to button returned of theResult
    end if
    
    if (gotButton is "Dictionary") then
        lookupInDictionary(gotValue)
        
        --delay 1
        
        set targetApp to application "Dictionary"
        
        lookupInLogophile(targetApp)
    else if (gotButton is "Google") then
        set theResult to display dialog "Please select search or translation." & return & return & "Search word(s): " & gotValue buttons {"Search", "Both", "Translation"} default button 2
        set gotButton to button returned of theResult
        
        set wordsNumber to count of word in gotValue
        set search_string to my myUrlEncode(gotValue)
        
        if gotButton is "Search" then
            set locationURL_g_sr to target_URL_g_sr & search_string as Unicode text
            open location locationURL_g_sr --検索結果ページを開きます
        else if gotButton is "Translation" then
            set locationURL_g_tr to target_URL_g_tr & search_string as Unicode text
            open location locationURL_g_tr --検索結果ページを開きます
        else if gotButton is "Both" then
            set locationURL_g_sr to target_URL_g_sr & search_string as Unicode text
            set locationURL_g_tr to target_URL_g_tr & search_string as Unicode text
            open location locationURL_g_sr --検索結果ページを開きます
            open location locationURL_g_tr --検索結果ページを開きます
        end if
    end if
    
end run

--------------------サブルーチン--------------------

on trim(theseCharacters, someText)
    --下記URL記載のものを若干修正して流用
    --http://macscripter.net/viewtopic.php?id=18519
    -- Lazy default (AppleScript doesn't support default values)
    if theseCharacters is true then set theseCharacters to ¬
        {space, tab, linefeed, return, ASCII character 0}
    -- ASCII character 0 は NUL(null文字)
    
    repeat until first character of someText is not in theseCharacters
        set someText to text 2 thru -1 of someText
    end repeat
    
    repeat until last character of someText is not in theseCharacters
        set someText to text 1 thru -2 of someText
    end repeat
    
    return someText
end trim

on getStringAtFrontMostApp()
    set frontmostApp to path to frontmost application
    tell application "Finder"
        set appName to name of frontmostApp
    end tell
    --display dialog appName
    if appName ends with ".app" then
        set appName to text 1 thru -5 of appName
    end if
    
    activate application appName
    tell application "System Events"
        tell application process appName
            keystroke "c" using command down
        end tell
    end tell
    
    delay 1
    
    tell application appName
        try
            set theText to the clipboard as Unicode text
        on error
            set theText to ""
        end try
    end tell
    
    return theText
end getStringAtFrontMostApp

on lookupInLogophile(targetApp)
    --set frontmostApp to path to frontmost application
    set frontmostApp to path to targetApp
    tell application "Finder"
        set appName to name of frontmostApp
    end tell
    
    if appName ends with ".app" then
        set appName to text 1 thru -5 of appName
    end if
    
    activate application appName
    tell application "System Events"
        tell application process appName
            keystroke "e" using {command down, shift down}
        end tell
    end tell
    activate application "Logophile"
end lookupInLogophile

on lookupInDictionary(gotValue)
    
    try
        set myWordForSearch to gotValue as Unicode text
    on error
        set myWordForSearch to ""
    end try
    
    if myWordForSearch is not "" then
        set escapedMyWordForSearch to my escapeForShellScript(myWordForSearch)
        --display dialog escapedMyWordForSearch
        set myURL to "dict://" & escapedMyWordForSearch as Unicode text
        --display dialog myURL
        set myShellScript to "open '" & myURL & "'"
        --display dialog myShellScript
        --open location myURL  --「付属」等ローマ字以外の文字列を渡すと開けない?
        do shell script myShellScript
        activate application "Dictionary"
    else
        say "No word is available."
        activate application "Dictionary"
    end if
end lookupInDictionary

on escapeForShellScript(theText)
    --最初は単純にエスケープ文字に置換したがうまくいかなかったので、URLエンコーディングの表現に置換するようにした。
    --下記のwebツールで変換した
    --http://www.tagindex.com/tool/url.html
    set modifiedText to theText
    if (offset of "'" in modifiedText) > 0 then
        --set modifiedText to my replaceText(modifiedText, "'", "\\'") -- %27
        set modifiedText to my replaceText(modifiedText, "'", "%27") -- %27
    end if
    if (offset of "\"" in modifiedText) > 0 then
        --set modifiedText to my replaceText(modifiedText, "\"", "\\\"")
        set modifiedText to my replaceText(modifiedText, "\"", "%22")
    end if
    return modifiedText
end escapeForShellScript

--以下はurlエンコーディングする関数、「python」を使用
--urlエンコーディングは下記URLのページを参照
--http://www2.airnet.ne.jp/~kenshi/mac08.html

on myUrlEncode(sourceText)
    do shell script "python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of sourceText -- python で URL エンコードする。
    set encodedText to the result -- 結果を取得する。
    return encodedText
end myUrlEncode


on devText(theText, aDelimiter)
    set tmp to AppleScript's text item delimiters
    set AppleScript's text item delimiters to aDelimiter
    set theList to every text item of theText
    set AppleScript's text item delimiters to tmp
    return theList
end devText

on joinList(theList, aDelimiter)
    set tmp to AppleScript's text item delimiters
    set AppleScript's text item delimiters to aDelimiter
    set theText to theList as string
    set AppleScript's text item delimiters to tmp
    return theText
end joinList

on replaceText(theText, serchStr, replaceStr)
    set tmp to AppleScript's text item delimiters
    set AppleScript's text item delimiters to serchStr
    set theList to every text item of theText
    set AppleScript's text item delimiters to replaceStr
    set theText to theList as string
    set AppleScript's text item delimiters to tmp
    return theText
end replaceText

LaTeX で日本語組版するためのメモ

LaTeX で日本語組版するためのメモ。

pLaTeX 使用前提。

基本的なコマンド

dviファイルの生成。

外部コマンドを実行する場合は-shell-escapeオプションを付ける。

文字コードを指定するときは--kanji=utfなどのオプションを付ける。

文字コード オプション指定
EUC-JP -kanji=euc
JIS -kanji=jis
SJIS -kanji=sjis
UTF-8 -kanji=utf
platex <TeXファイル名>

dviファイルからPDFを生成。

dvipdfmx <dviファイル名>

PDFファイルを直接生成。

ptex2pdf -l <TeXファイル名>

索引スタイルファイル(ist)の処理。

mendex -s <ファイル名>.ist <ファイル名>.idx

エラーが起きたとき

  • 続行:そのままEnterキーを押す。
  • 中断:xを入力してEnterキーを押す。
  • エラーを表示せずに続行:qを入力してEnterキーを押す。

エラーメッセージ類

  1. TeX のエラーメッセージ - TeX Wiki
  2. LaTeX のエラーメッセージ - TeX Wiki
  3. LaTeX の警告メッセージ - TeX Wiki

基本的な文書構造

\documentclass{jsarticle}
\begin{document}
hoge
\end{document}

LaTeX文書のコマンド

マクロを定義するコマンド

  • \newcommand:新規定義する。定義済みのコマンド名とかぶる場合はエラー。
  • \providecommand:新規定義する。定義済みのコマンドとかぶる場合は定義済みを優先。
  • \renewcommand:既存コマンドを再定義する。未定義コマンドには使えない。
  • \DeclareRobustCommand:定義済みのコマンドとかぶる場合は無条件に上書き。
  • \def:定義済みのコマンドとかぶる場合は無条件に上書き。

okumacroの倍角ダッシュのコマンド

\−−
\--
\――

調べる

コマンド名等のドキュメントを参照する。

該当するマニュアルが複数ありうる場合は-lオプションをつけると当てはまるものがリストされる。

texdoc <コマンド名等>

TeX関連のファイルの場所を検索する。

kpsewhich <ファイル名等>

「CTAN: Search」で検索する。

情報源

オンライン

  1. TeX Wiki
  2. TeXの本 - TeX Wiki
  3. TeXの話
  4. TeX/LaTeX入門 - Wikibooks

マクロ

  1. LaTeX入門/LaTeXマクロの作成 - TeX Wiki
  2. TeX入門/マクロの作成 - TeX Wiki
  3. 「LaTeX2e まくろの八衢」オンライン版(PDF)

クラスファイル

  1. にっき♪: クラスファイルを作ろう (1)(宣言、フォント等)
  2. にっき♪: クラスファイルを作ろう (2)(文字サイズ等)
  3. にっき♪: クラスファイルを作ろう (3)(紙サイズ等)
  4. にっき♪: クラスファイルを作ろう (4)(見出し等)
  5. にっき♪: クラスファイルを作ろう (5)(柱等)
  6. にっき♪: クラスファイルを作ろう (6)(\maketitleやabstract環境等)
  7. にっき♪: クラスファイルを作ろう (7)(リスト系等)

  8. LaTeX2ε for class and package writers

TeXのバージョン管理

  1. 『数式組版』を組む技術:複数のTeX Liveバージョンとtexmf-treeとを管理する|きえだゆうすけ(p_typo)

書籍

  1. [改訂第8版]LaTeX2ε美文書作成入門:書籍案内|技術評論社
  2. 独習LaTeX2ε(吉永 徹美)|翔泳社の本

多言語組版の資料

多言語組版において、参考になる資料等。

  1. 多言語組版について | 多言語フォント | モリサワのフォント | 株式会社モリサワ
    • 欧文、中国語、韓国語、タイ語についての資料がある。
  2. 多言語組版研究会
    • 欧文、韓国語、アラビア系文字についての資料がある。
    • a batons rompus(欧文の資料)
    • Wayback Machine(アラビア系文字の資料)
  3. 中国語における句読点の基本的な用法 - しろもじ作業室

A3のPDFをA4に分割したい

A3のPDFをA4用紙にプリントするのにA4に分割したいと思って、ググったらそのまんまの webサービスがあったのでメモ。

Microsoft Outlook for Mac 2011 から 2021 へ別の Mac に移行する

どうも Microsoft Outlook for Mac 2021 は癖があるらしく、ググってみても少し戸惑ったのでメモ。

試した環境は次のような感じ。

移行元:

移行先:

行った手順

  1. Outlook for Mac 2021」はまだ設定等していない状態。
  2. 移行元の[ホームフォルダ]→[書類]→[Microsoft ユーザー データ]の[Office 2011 Identities]フォルダを移行先の[ホームフォルダ]→[書類]→[Microsoft ユーザー データ]にコピー。(サイズが大きいので実際はzip圧縮してコピーして解凍した。)
  3. Outlook for Mac 2021」を起動。
  4. Outlook]メニューからチェックマーク付きの[新しい Outlook]メニューを選択し、古いバージョンに戻す。(自分の環境では「新しい Outlook」に戻せなくなったので注意。)
  5. [ファイル]メニューから[インポート…]メニューを選択し、[このコンピュータ上のOutlook 2011データ]を選択した状態で[続行]を押す。以降、画面の指示に従う。
  6. [ツール]メニューから[アカウント…]メニューを選択し、各種アカウントのパスワードを設定する。
  7. Outlook for Mac 2021」の動作確認をしたらコピーした「Office 2011 Identities」はゴミ箱に捨ててOK。
  8. 「新しい Outlook」に戻して完了…としたいところだが、当方の環境の「Outlook for Mac 2021」には「新しい Outlook」に戻すボタンもメニューも見当たらないので「新しい Outlook」に戻せないまま。

参照ページ

  1. MAC導入メモ - Qiita
  2. Outlook for Mac 2011から2016へのアップデートは簡単 | シャンハイリンゴ
  3. Mac Office2019 Outlook2011から2019に移行(履歴も設定もまるごと移植) - やろうとおもったときができるとき
  4. Microsoft、全く新しいデザインを採用した「Outlook for Mac v16.58」をMac App Storeでリリース。
  5. Outlook for Mac最新版で使い方が依然と違う!を即解決できる方法。リボンがない・オプションや後で送信表示がない時に。 | ちょいっと小学生
  6. Outlook 2021 for Macの設定手順
  7. Microsoft、Mac版「Outlook」を無償化 - 窓の杜

Finderで最前面のウィンドウの名前でファイル名を作成日時順に連番でつけるAppleScript

Finderで最前面のウィンドウの名前でファイル名を作成日時順に連番でつけるAppleScript

自炊したPDFをとりあえずリネームさせる用に書いた。

tell application "Finder"
    set targetWindow to front window
    set baseName to name of targetWindow
    set targetFiles to files in targetWindow
    set targetFiles to sort targetFiles by creation date
    
    set i to 1
    repeat with targetFile in targetFiles
        set currentExtension to name extension of targetFile
        set newName to baseName & "-" & i & "." & currentExtension
        try
            set name of targetFile to newName
        on error errStr number errorNumber
            display dialog errStr
        end try
        set i to i + 1
    end repeat
    
end tell

参照ページ:

  1. Applescript -ドロップされたファイルのソート- - ちくちく日記

  2. 指定ファイルの拡張子を取得する – AppleScriptの穴

新しいMacを買ったのでセットアップのメモ

新しめのOSを動かす用に新しいMacを買ったのでセットアップのメモ。 まあ、中古だけど。

OSはとりあえずCatalinaで様子見。(なんやかんやでMontereyにアップデート(2023-04-29追記))

あらためて入れるアプリケーション等。

  1. Google Chrome
  2. Google 日本語入力
  3. Window Tidy
  4. Homebrew
  5. Slack
  6. VSCode
  7. Cyberduck
  8. Logophile
  9. DeepL
  10. PFKeyAvailerX
  11. Get Plain Text
  12. mi
  13. CotEditor(Catalinaはサポートしていなかったので保留。)
  14. QLMarkdown brew install --cask qlmarkdown

参考記事:

  1. Mac の Finder で Markdown ファイルをクイックルックでプレビューしたい - ぼんやりDTP