0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Keynoteからの書き出しで変なcharが入る

Last updated at Posted at 2023-06-28

症状

Keynoteから画像を書き出すときに,名前に変なコードが入る.lsとかでautocompleteできない.

解決法

原因とか,Keynoteのバージョンがわかんなかったので,とりあえず,Ruby コードでconverterを作った.役立つかな???

コード

 1  dir = './'
 2  Dir.glob(dir+"*.*").each do |name|
 3    p name
 4    p name.bytes
 5    correct_name = name.bytes.collect do |bb|
 6      bb.chr if bb< 128
 7    end
 8    p target = correct_name.join("")
 9    p target == name
10    system "mv #{name} #{target}"
11  end

結果

こいつを動かすと,

> ruby ../del_invisible_chars.rb
"./‎figs.‎001.png"
[46, 47, 226, 128, 142, 102, 105, 103, 115, 46, 226, 128, 142, 48, 48, 49, 46, 112, 110, 103]
"./figs.001.png"
false
"./‎figs.‎002.png"
[46, 47, 226, 128, 142, 102, 105, 103, 115, 46, 226, 128, 142, 48, 48, 50, 46, 112, 110, 103]
"./figs.002.png"
false
"./‎figs.‎003.png"
[46, 47, 226, 128, 142, 102, 105, 103, 115, 46, 226, 128, 142, 48, 48, 51, 46, 112, 110, 103]
"./figs.003.png"
false

となります.fishとかFinderでは見た目一緒なんですが.あ,emacsにpasteすると見えますね.でも,Qiitaでは表示されない.上の出力では,

[226, 128, 142]

ですね.浸入の原因はわかりません.ネットにはそれらしい情報がなくて,ご存知ならお教えください.

Another code <2023-08-22 火>

検索がうまくいかなくて,見つけられず,新たなコードを書いてしまいました.やれやれ.

ただ,こっちの方が直感的かも.

  #!/usr/bin/env ruby
  require 'fileutils'

  p files = ARGV[0]
  puts "Usage: del_invisible_charc \'./*.png\'";exit unless files
  # optionとしてシングルクォート付で指定すべし,
  # するとshellで展開されずにRubyで処理

  Dir.glob(files).each do |file|
    puts file
    t_file = ''
    file.each_codepoint do |s| # 各コードポイントで呼び出し
      #    p s.to_s(16) # 16進数で表示
      t_file << s unless s.to_s(16) == "200e" # こいつが悪さしてるので削除
    end
    puts t_file
    puts file == t_file
    next if file == t_file
    FileUtils.mv(file, t_file, verbose: true)
  end

  • source ~/bin/del_invisible_chars.org
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?