bar_1

contents_map

2022年10月16日日曜日

[macOS]外付けストレージのボリュームラベルを変更したいがグレーアウトしていて変更できない場合の対処法

小ネタ. ずっと困っていたけど, 先ほど解決できたので.

* OS macOS Monterey 12.6
* ディスクユーティリティ 21.5
* 外付けストレージ SSD 500GB. USB 外部物理ディスク・GUIDパーティションマップ/APFSコンテナ/APFSボリュームグループ・APFS


1. ディスクユーティリティを起動して, 当該ボリュームを選択
2. 取り出しかマウント解除をする
3. 再度マウントする
4. 右ペインのラベル名をクリックして, 変更する

1〜3を行うと, ディスクユーティリティの右ペインにある, ボリュームラベルの名前が, グレーから白い文字になる. この状態でクリックして変更できるようになっている (なんでだよw).

brewでインストールする際に, まれにパスにスペースを含まないことを前提とするものがあり, 困っていた.

2022年10月14日金曜日

OyayubiKE: Karabiner-Elements 14.10.0 でmacOS上の親指シフト環境を構築する2022

OyayubiKE: Karabiner-Elements 14.10.0 でmacOS上の親指シフト環境を構築する2022

2022-10-05

Karabiner-Elements (KE) を 14.10.0 にバージョンアップしたところ, だましだまし使っていた自前の親指シフト環境が使えなくなってしまった.

そこで今回, 以前リリースしたものを思い切って全面的に見直し, 新たにOyayubiKE
と称することとした. 一応使えるレベル (完成度は自己評価で51%くらい) にはなったと思うので公開する.
が……後述のように 一定の不具合は存在するので注意すること.

OyayubiKEの動作確認した環境

動作確認した環境は以下の通り:

  • ハードウェア環境
    • Mac本体: Mac mini (M1,2020)
    • USB Hub: ELECOM 2x7 USB switch U2SW-B27SBK
    • USB Keyboard: Logicool K120 (ごく一般的な日本語JIS 109キーボードです)
  • ソフトウェア環境
    • OS macOS Monterey 12.6
    • IME 日本語入力プログラム(Kotoeri)
    • Krabiner-Elements 14.10.0
  • 動作確認したソフト
    • ブラウザ - Safari, Brave.
    • エディタ等 - ターミナル.app, ターミナル上のvim, Visual Studio Code (+vscodevim).
    • その他アプリ - Libre Office (Writer), Discord, League of Legends.

2019年12月25日水曜日

Karabiner-Elementsだけで親指シフト環境を構築(2019年版)


以前, Karabiner-Elements (以下, KE)だけで親指シフト環境を構築した. これはKEのバージョンアップのいつかのタイミングで, 不具合が発生するようになっていた.
この不具合について今回対策を試みたので, 本記事で2019年版として紹介する. 確認したのは以下の環境である:
  • OS: macOS High Sierra 10.13.6
  • IME: Google 日本語入力 2.25.3700.1(ローマ字入力)
  • Karabiner-Elements: 12.8.0
  • システム環境|キーボード>キーボード>修飾キー…のKarabiner VirtualHIDKeyboardの設定: デフォルト
  • キーボード: USB接続のJISキーボード Logicool K120
なお今回提案の親指シフト環境で, システム環境設定でのキーボード設定で修飾キーの入れ替えをしている場合, 分節調整(Ctrl-I, Ctrl-O)がうまく動作しなくなることを, 筆者は確認している. 原因は不明である

2019年5月16日木曜日

macOSでマウスカーソルがウィンドウにくっついてしまうなどの現象の対処法

最近, macOSでマウスカーソルがウィンドウにくっついてしまう現象が生じた. 以降の操作が何もできなくなってしまうのでとても困る. 環境は以下の通りである:
  • macOS High Sierra 10.13.6
これとは別のケースで, ウィンドウがアクティブにならなくなってしまう現象は前から稀に起きていた. これら2つの不具合の対処方法を示す.

2018年12月25日火曜日

calendar_days.gem ドキュメント

平日のみの日を取得するためのライブラリcalendar_days.gemを作った.

以下, 下書き

2018年12月21日金曜日

Thor ジェネレータ Generators

ジェネレータ Generators

Thorのすぐれた利用方法のひとつは, カスタムのコード・ジェネレータを作ることだ.
Thor::Group, Thor::Actions そしてERBテンプレート群とを組み合わせれば, これをとても簡単に実現できる (訳注: Thorはもともとrakeやsakeの代替えとして開発されていたようだ. ). ここに例を示そう:
A great use for Thor is creating custom generators. Combining Thor::Group,
Thor::Actions and ERB templates makes this very easy. Here is an example:
class Newgem < Thor::Group
  include Thor::Actions

  # もろもろの引数とオプションを定義する
  # Define arguments and options
  argument :name
  class_option :test_framework, :default => :test_unit

  def self.source_root
    File.dirname(__FILE__)
  end

  def create_lib_file
    template('templates/newgem.tt', "#{name}/lib/#{name}.rb")
  end

  def create_test_file
    test = options[:test_framework] == "rspec" ? :spec : :test
    create_file "#{name}/#{test}/#{name}_#{test}.rb"
  end

  def copy_licence
    if yes?("Use MIT license?")
      # source rootディレクトリでMITLICENSEファイルをコピーする
      # Make a copy of the MITLICENSE file at the source root
      copy_file "MITLICENSE", "#{name}/MITLICENSE"
    else
      say "Shame on you…", :red
    end
  end
end
thor -T を実行すると, このジェネレータの使い方を表示する. それは thor newgem NAME を読むはずだ. これはジェネレータを実行するのに, われわれはNAMEという引数を与えなければならないことを示している.
Doing a thor -T will show how to run our generator. It should read:
thor newgem NAME. This shows that we have to supply a NAME
argument for our generator to run.
create_lib_file はERBテンプレートのひとつを使っている. これはこのようになる:
The create_lib_file uses an ERB template. This is what it looks like:
class <%= name.capitalize %>
end
あなたがジェネレータの中で設定した引数たちは template が呼び出されたときに, 自動で渡される. その他のオプション詳細は ドキュメント を読んで確認せよ.
The arguments that you set in your generator will automatically be passed in
when template gets called. Be sure to read the documentation for more options.
ジェネレータを thor newgem devise で実行すると, ふたつのファイルが作られる: “devise/lib/devise.rb” と “devise/test/devise_test.rb” だ. その次にユーザは, (yes? メソッドを使ったプロンプトで) MITライセンスのファイルをコピーしたいかどうかたずねられる.
もしテスト・フレームワークを変えたいなら, オプションを: thor newgem devise --test-framework=rspec のように追加できる. これはふたつのファイル: “devise/lib/devise.rb” と “devise/spec/devise_spec.rb” を生成する.
Running the generator with thor newgem devise will create two files: “devise/lib/devise.rb”, and “devise/test/devise_test.rb”. The user will then be asked (via a prompt by the yes? method) whether or not they would like to copy the MIT License. If you want to change the test framework, you can add the option: thor newgem devise --test-framework=rspec.
This will generate two files: “devise/lib/devise.rb” and “devise/spec/devise_spec.rb”.

Thor 実行ファイルを作る Making An Executable

実行ファイルを作る Making An Executable

あなたはスクリプトをひとつの実行可能コマンドとして作りたいかもしれない. これをThorで行うには:
You may want to make a script as an executable command. To do this with Thor:
  • RubyのShebang行 (訳注: #! で始まる実行スクリプトの最初の一行目) を入れる.
  • スクリプトの中で require "thor" する.
  • あなたのThorクラスを定義する.
  • #{YourThorClassname}.start を最下行に書く (訳注: .start(ary)とすると明示的に渡せる. この例のようにaryを指定しないとARGVが自動で使われる).
  • include the ruby shebang line.
  • require “thor” in your script.
  • define your Thor class.
  • add #{YourThorClassname}.start to the bottom of your script.
例: mythorcommand.rb
Example: mythorcommand.rb
#!/usr/bin/env ruby
require "rubygems" # ruby1.9 doesn't "require" it though
require "thor"

class MyThorCommand < Thor
  desc "foo", "Prints foo"
  def foo
    puts "foo"
  end
end

MyThorCommand.start
スクリプトを実行可能にする:
Make the script executable:
chmod a+x mythorcommand.rb
今このようにタイプして実行できる:
Now you can type:
./mythorcommand.rb foo

Thor 名前空間 Namespaces

名前空間 Namespaces

デフォルトでは, あなたのThorタスクはRubyの名前空間を使って実行される. このクラスは名前空間を持たない:
By default, your Thor tasks are invoked using Ruby namespace. This class has no namespace:
class App < Thor
  desc 'install', 'Install something'
  def install
    # task code
  end
  # other tasks
end
このクラスのもろもろのタスクは以下のように実行される:
Its tasks are invoked as:
thor app:install
しかしながら, あなたはクラスに名前空間を付けることもできる:
However, you could namespace your class as:
module Sinatra
  class App < Thor
    desc 'install', 'Install something'
    def install
      # task code
    end
    # other tasks
  end
end
そうしたらこのようにこのタスクを実行すればよい:
And then you should invoke your tasks as:
thor sinatra:app:install
お望みならば, 名前空間をこのように変えることもできる:
If desired, you can change the namespace:
module Sinatra
  class App < Thor
    namespace :myapp
    def install
      # task code
    end
    # other tasks
  end
end
そうしたときは, このようにして, あなたのもろもろのタスクは実行されるはずだ.
And then your tasks should be invoked as:
thor myapp:install

Thor アクション Actions

アクション Actions

Thorには, スクリプトやジェネレータといったタスクに役立つ, 5,6個のアクションがある. いくつかはRailsのテンプレートとしてあるので, あなたはそれらに親しんでいるかもしれない. 列挙すると: say, ask, yes?, no?, add_file, remove_file, copy_file, template, directory, inside, run, inject_into_file や, その他にも2,3ある.
Thor comes with several actions that help with script and generator tasks. You might be familiar with them since some came from Rails Templates. They are: say, ask, yes?, no?, add_file, remove_file, copy_file, template, directory, inside, run, inject_into_file and a couple more.
これらを使うには, あなたのThorクラスたちの中で Thor::Actions をincludeするだけだ:
To use them, you just need to include Thor::Actions in your Thor classes:
class App < Thor
  include Thor::Actions
  # tasks
end
ファイルをコピーするアクションなどように, アクションによっては source_root と呼ばれる, クラスメソッドがひとつ必要となるアクションもある. このクラスメソッドはあなたのテンプレートたちが配置されているべきディレクトリだ. Thor::ActionsThor::Shell::Basic のドキュメントを確認すること. たとえば:
Some actions like copy file require that a class method called source_root be defined in your class. This is the directory where your templates should be placed. Be sure to check the documentation on Thor::Actions and Thor::Shell::Basic. For instance:
class App < Thor
  include Thor::Actions

  def self.source_root
    File.dirname(__FILE__)
  end
end

Thor グループ Groups

グループ Groups

Thorには Thor::Group という特別なクラスがある. ひとつの Thor::Group に 定義されたもろもろのタスクはすべて, それらが定義された順に, ひとつのシーケンスとして実行される. [[実行 Invocations]] で使った例は Thor::Group を使って, このように書ける:
Thor has a special class called Thor::Group. All of the tasks defined in a Thor::Group are invoked together as a sequence, in the order that they were defined. The example from [[Invocations]] could be rewritten using
Thor::Group as:
myawesomegem/lib/mycounter_file.rb
require 'thor/group'

module MyAwesomeGem                 # 訳注: 名前空間のためのmodule
  class MyCounter < Thor::Group     # 訳注: ThorではなくThor::Group
    desc "Prints 1 2 3"

    def one
      puts 1
    end

    def two
      puts 2
    end

    def three
      puts 3
    end
  end
end
実行すると:
When invoked:
thor my_awesome_gem:my_counter
# prints "1 2 3"

実行ファイルexecutableのコマンド・リストに, サブクラスThor::Groupを追加するためには, 一番最初に, あなたはこの登録をしなければならないという点に, 注意すること.
Note that in order to add the Thor::Group subclass to the commands list of your executable, you have to register it first.
実行ファイルを利用するには, 説明が [[実行ファイルの作成 Making An Executable]] にあり, たとえばこのようなファイルがあるとする:
Building on the executables explanation found in [[Making An Executable]], let’s say that you have a file:
myawesomegem/bin/command
#!/usr/bin/env ruby
require File.expand_path('lib/command', Dir.pwd)
MyAwesomeGem::MyCommand.start
そうして, コマンドの実装を含むファイルは以下:
And then, the file containing the actual command:
myawesomegem/lib/command.rb
require "thor"
module MyAwesomeGem
  class MyCommand < Thor
    desc "foo", "Prints foo"
    def foo
      puts "foo"
    end
  end
end
実行ファイルをテストする:
Test executable file:
cd myawesomegem
chmod a+x bin/command # make permission
bin/command foo
クラス MyCounterサブコマンドとして 使えるようにするには, Thor.registerメソッド をコールする必要がある:
To make MyCounter available as a subcommand, you need to call the register method:
myawesomegem/lib/command.rb
require "thor"
require File.expand_path("lib/mycounter_file", Dir.pwd)
module MyAwesomeGem
  class MyCommand < Thor
    desc "foo", "Prints foo"
    def foo
      puts "foo"
    end

    # register(class_name, subcommand_alias, usage_list_string, description_string)
    register(MyAwesomeGem::MyCounter, "counter", "counter", "Prints some numbers in sequence")
  end
end
今, クラス MyAwesomeGem::MyCounter < Thor::Group は, mycommand の中のサブタスクとして現れ, そのエイリアスは counter となり, 使い方は:
Now the class MyCounter < Thor::Group will appear as a sub-task within mycommand with the alias counter, usage:
bin/command
# Commands:
#  command counter         # Prints numbers in sequence
#  command foo             # Prints foo

bin/command counter
#=> 1 2 3

注意: Thor::Group を使う場合は, あなたが (descメソッドで) 用意した説明書きは, それぞれのタスク毎にひとつの説明が用意されるのではなく, クラスそのものの説明書きとなる.
Note: when using Thor::Group, the description you provide (using the method desc) is for the entire class, as opposed to providing a description for each task.
また, Thor::Group はもろもろの引数 arguments とオプションをThorのタスクとしてパースできる:
Also, Thor::Group can parse arguments and options as Thor tasks:
class Counter < Thor::Group
  # number will be available as attr_accessor
  argument :number, :type => :numeric, :desc => "The number to start counting"
  desc "Prints the 'number' given upto 'number+2'"

  def one
    puts number + 0
  end

  def two
    puts number + 1
  end

  def three
    puts number + 2
  end
end
上記counterはひとつのパラメータを期待するものであり, 下記のような出力が得られる:
The counter above expects one parameter and has the following outputs:
thor counter 5
# Prints "5 6 7"

thor counter 11
# Prints "11 12 13"
あなたはまた, もろもろのオプションを Thor::Group に与えることができるが, method_optionmethod_options の代わりに, class_optionclass_options を使ってもいい. argument メソッドと class_optionsメソッドは両方とも, Thorクラスにも使用可能だ.
You can also give options to Thor::Group, but instead of using method_option
and method_options, you should use class_option and class_options.
Both argument and class_options methods are available to Thor class as well.
Thor::Group は, 定義された順に実行される5,6個のステップで定義できるので, ジェネレータを作るのにすぐれたツールのひとつだ (Thor::Group は Rails 4.x のジェネレータに使われているツールだ. 訳注: Rails 5.xでもジェネレータとして使われている痕跡が残っている)
Thor::Group is a great tool to create generators, since you can define several steps which are invoked in the order they are defined (Thor::Group is the tool used for generators in Rails 4.x).