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 5 years have passed since last update.

Macのデフォの状態でとったスクリーンショットを整理するだけのメモ

Posted at

スクショの整理(日本語環境のMACのデフォの設定)

日本語環境でMac(筆者はHigh Sierra)環境でスクショをとるとデスクトップに(スクリーンショット yyyy-mm-dd h.mm.ss.png)みたいな感じで保存されると思うのですが、けっこう鬱陶しいので(コマンドラインで設定すれば保存先も形式も設定出来ます、がデスクトップから即座に消えるのはそれはそれで探すのがめんどくさい)デスクトップにスクショがあるときに自動で日付順のディレクトリと名前に整理するだけのpythonプログラムを作りました

スクリーンショット 2020-04-23 1.01.30.png
screenshot_sort_mac.py
# !/usr/bin/env python
# coding: utf-8


import os
import shutil

path = "/Users/user/Desktop/" # 保存先を
os.chdir(path)
files = os.listdir()


def change_file_name_png(x):
    str_files = x.replace(" ", "")
    str_files = str_files.replace(".", "")
    str_files = str_files.replace("-", '')
    str_files = str_files.replace("png", "")

    if "スクリーンショット" in str_files: # 二つのif文でファイル名を強引に簡単にしてる、for文等を使って連番にするのもよし
        str_files = str_files.replace("スクリーンショット", "Pict")
    else:
        break # スクリーンショット以外を処理させないため

    if "20" in str_files:
        cnt = str_files.index("20")

        file_date = str(str_files[4:10])
        str_files = str_files.replace(file_date, "")
    else:
        file_date = "PNG"

    if os.path.exists(path + "Screenshots/" + file_date + "/") == False:
        os.makedirs(path + "Screenshots/" + file_date + "/")
        os.chmod(path + "Screenshots/" + file_date + "/", 0o744)

    else:
        pass

    shutil.move(path + x, path + "Screenshots/" + file_date + "/" + str_files + ".png")

for i in files:
    if ".png" in i: # 移動するターゲットファイルの形式は自由に
        change_file_name_png(i)

print('finish')

MACのスクショは
command + shift + 3  (4だと部分的なスクショも可能)

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?