320x100

2024.03.07 - [나의 그냥 일상(Just My Daily Life)] - [1분 꿀팁] 생성형 AI와 대화하면서 맥OS 자동화 스크립트 만들기 1편

 

[1분 꿀팁] 생성형 AI와 대화하면서 맥OS 자동화 스크립트 만들기 1편

나는 3년 넘게 맥미니 m1을 사용하고 있는 진성 애플유저였다. 사실 윈도우냐 맥이냐는 중요하지 않았다. 내가 주로 하는 컴퓨터 활동은 기기에 구애를 받지 않기 때문에. 하지만 가끔 나는 특정

npo-archiving.tistory.com

 

2024.03.10 - [나의 그냥 일상(Just My Daily Life)] - [1분 꿀팁] 생성형 AI와 대화하면서 맥OS 자동화 스크립트 만들기 2편

 

[1분 꿀팁] 생성형 AI와 대화하면서 맥OS 자동화 스크립트 만들기 2편

2024.03.07 - [나의 그냥 일상(Just My Daily Life)] - [1분 꿀팁] 생성형 AI와 대화하면서 맥OS 자동화 스크립트 만들기 1편 [1분 꿀팁] 생성형 AI와 대화하면서 맥OS 자동화 스크립트 만들기 1편 나는 3년 넘게

npo-archiving.tistory.com

 

on randomStringWithLength(len) 
    set chars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set theString to ""
    repeat len times
        set theString to (theString & item (random number from 1 to length of chars) of chars)
    end repeat
    return theString
end randomStringWithLength

tell application "Finder"
    set homeFolderPath to (path to downloads folder as string)
    set theFolder to homeFolderPath & "temp:"
    set theFiles to every file in folder theFolder whose name extension is "png"
    log "Found " & (count theFiles) & " files."
    repeat with aFile in theFiles
        set newName to randomStringWithLength(10) & ".png"
        log "Renaming " & (name of aFile) & " to " & newName
        set name of aFile to newName
    end repeat
end tell

 

이제 에러 메세지는 안뜨지만 정작 원하는 결과물은 나오지 않는다.

 

 

on randomStringWithLength(len) 
    set chars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set theString to ""
    repeat len times
        set theString to (theString & item (random number from 1 to length of chars) of chars)
    end repeat
    return theString
end randomStringWithLength

tell application "System Events"
    set homeFolderPath to (path to downloads folder as string)
    set theFolder to homeFolderPath & "temp:"
    set theFiles to every file in folder theFolder whose name extension is "png"
    log "Found " & (count theFiles) & " files."
    repeat with aFile in theFiles
        set newName to randomStringWithLength(10) & ".png"
        log "Renaming " & (name of aFile) & " to " & newName
        set name of aFile to newName
    end repeat
end tell

 

그래서 디버깅 로그가 뜨는 코드를 추가했지만 디버깅 로그도 뜨지 않는다.

 

결국 AppleScript를 포기하고 다시 터미널에서 진행하는 걸로 전략을 바꾼다.

 

여전히 버튼 하나로 자동화를 꿈꾸는 과거에서 배우지 못한자.

 

 

find /path/to/your/folder -type f \( -name "*.mp4" -o -name "*.mkv" -o -name "*.avi" \) -exec mv {} /path/to/your/folder/.. \;

 

위에서 제시한 방법으로 하기에는 급 귀찮아져서, 새로운 코드를 요청해보았다. 동영상 파일을 추려서 바로 윗단계 폴더로 옮기고 싶은데 폴더창을 2개씩 띄우지 않고 역시 한번에 하고 싶어졌다.

 

 

mv /path/to/source/folder/*.txt /path/to/destination/folder/

 

cp /path/to/source/folder/*.txt /path/to/destination/folder/

 

뭔가 더 알려주었지만 자동화하는 방법을 알지 못해 여기까지만 물어보기로 했다. 

 

그래서 결국 파일명 바꾸는 것은 성공했냐고?

 

물론이다. 

 

 

터미널을 켜고

cd ~/downloads/temp

for file in *; do
  mv "$file" $(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1).png
done

 

자기가 바꾸고 싶은 폴더 위치를 첫 줄 코드에 입력하고(나는 다운로드 폴더 안에 temp 폴더를 만들었다.)

 

엔터를 친다.

 

 

 

그 다음 2~3번째 코드를 입력한다.

 

 

 

폴더에 들어가 있는 파일 숫자에 따라 시간이 좀 지나면서 새로운 명령어 줄이 생기면 완료이다.

 

 

그럼 이렇게 랜덤으로 파일명이 바뀌게 된다.

 


 

여기까지가 생성형 AI로 대화하면서 코딩은 전혀 모르는 문과 전공이 코딩을 해본 경험이다.

 

위의 코딩은 자동화에는 실패해서 메모장에 넣어놓고 필요할때마다 복붙해서 사용하고 있다.

 

전문 프로그래머라면 더 간단하게 할 수 있겠지만, 생성형 AI 덕분에 hello world 만 할 줄 아는 문과생도 내가 원하는 만큼 자동화를 할 수 있게 되었다. 

 

여기까지 봐준 독자분께 고생과 감사를 표하며 "생성형 AI와 대화하며 맥OS 자동화 스크립트 만들기" 시리즈는 여기서 마무리하겠다.

 

 

320x100
320x100

2024.03.07 - [나의 그냥 일상(Just My Daily Life)] - [1분 꿀팁] 생성형 AI와 대화하면서 맥OS 자동화 스크립트 만들기 1편

 

[1분 꿀팁] 생성형 AI와 대화하면서 맥OS 자동화 스크립트 만들기 1편

나는 3년 넘게 맥미니 m1을 사용하고 있는 진성 애플유저였다. 사실 윈도우냐 맥이냐는 중요하지 않았다. 내가 주로 하는 컴퓨터 활동은 기기에 구애를 받지 않기 때문에. 하지만 가끔 나는 특정

npo-archiving.tistory.com



생성형 ai와 시원시원한 답변과 그 답변 대비 내맘대로 되지 않는 답답함이 공존하는 가운데...

 

for file in /Users/YourUserName/Desktop/images/*; do
  mv "$file" $(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1).jpg
done

 

역시나 이해 할 수 없는 오류 메세지가 나왔고, 예시를 들면서 알려주는 AI

 

 

그리고 충격적이게 사라진 파일. 엄청나게 중요한 파일은 아니지만 말도 없이 사리진 파일을 이리저리 다시 찾아봤지만 찾을 수 없었다. 

 

결국 테스트용 파일을 잘라내기가 아닌 복사한 파일로 다시 시도해보았다.

 

tell application "Finder"
    set theFolder to (choose folder with prompt "Select the folder containing the files to rename:")
    set theFiles to every file in theFolder
    repeat with aFile in theFiles
        set theName to name of aFile
        set name of aFile to (random number from 1000 to 9999 as string) & theName
    end repeat
end tell

 

매 번 잊지 않고 백억을 하라고 충고해주는 우리의 친절한 AI.

 

하지만 Automator 로도, AppleScript로도 만드는 데 실패한 나.

 

 

on randomStringWithLength(len) 
    set chars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set theString to ""
    repeat len times
        set theString to (theString & item (random number from 1 to length of chars) of chars)
    end repeat
    return theString
end randomStringWithLength

tell application "Finder"
    set theFolder to (path to downloads folder as text) & "임시:"
    set theFiles to every file in theFolder whose name extension is "png"
    repeat with aFile in theFiles
        set name of aFile to (randomStringWithLength(10) & ".png")
    end repeat
end tell

 

아예 구체적으로 조건을 설정해주고 처음부터 다시 시작해보았다.

 

on randomStringWithLength(len) 
    set chars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set theString to ""
    repeat len times
        set theString to (theString & item (random number from 1 to length of chars) of chars)
    end repeat
    return theString
end randomStringWithLength

tell application "Finder"
    set theFolder to (path to downloads folder as text) & "Temp:"
    set theFiles to every file in theFolder whose name extension is "png"
    repeat with aFile in theFiles
        set name of aFile to (randomStringWithLength(10) & ".png")
    end repeat
end tell

 

미국 기업답게 폴더를 한글 이름으로 하면 인식 못한다고 한다. 그래서 영어로 폴더 이름을 바꾸고 다시 도전

 

 

on randomStringWithLength(len) 
    set chars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set theString to ""
    repeat len times
        set theString to (theString & item (random number from 1 to length of chars) of chars)
    end repeat
    return theString
end randomStringWithLength

tell application "Finder"
    set homeFolderPath to (path to home folder as string)
    set theFolder to homeFolderPath & "Downloads:Temp:"
    set theFiles to every file in theFolder whose name extension is "png"
    repeat with aFile in theFiles
        set name of aFile to (randomStringWithLength(10) & ".png")
    end repeat
end tell

 

 

on randomStringWithLength(len) 
    set chars to "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    set theString to ""
    repeat len times
        set theString to (theString & item (random number from 1 to length of chars) of chars)
    end repeat
    return theString
end randomStringWithLength

tell application "Finder"
    set homeFolderPath to (path to downloads folder as string)
    set theFolder to homeFolderPath & "temp:"
    set theFiles to every file in folder theFolder whose name extension is "png"
    repeat with aFile in theFiles
        set name of aFile to (randomStringWithLength(10) & ".png")
    end repeat
end tell

 

계속된 실패에도 화를 내지 않고 새로운 방법을 알려주는 살아있는 부처 AI

 

AI의 꾸준한 도움에 힘 입어 지치 않고 계속해서 도전하면서 최적의 방법을 찾을 수 있을까요?

 

to be continued...

320x100
320x100

나는 3년 넘게 맥미니 m1을 사용하고 있는 진성 애플유저였다. 사실 윈도우냐 맥이냐는 중요하지 않았다. 내가 주로 하는 컴퓨터 활동은 기기에 구애를 받지 않기 때문에. 하지만 가끔 나는 특정 파일들의 이름을 랜덤으로 설정하는 과정을 필요로 했다. 그래서 보통 일일이 파일을 클릭하고 엔터를 치고(맥 OS는 엔터가 이름 바꾸기), 그냥 키보드 막 누르고 엔터를 쳤다. 

 

하지만 그 파일이 50개가 넘어가면 손도 아프고, 무작위로 눌렀는데도 겹치는 경우가 생긴다. 이를 자동화하는 방법은 없을까 고민고민 끝에 AI를 활용해보기로 했다. 

 

내가 사용하는 AI 툴은 '뤼튼'으로 Chatgpt기반의 국내 AI 툴이다. 뤼튼의 자세한 설명은 생략하고 내가 이 AI 툴을 활용해서 어떻게 자동화가 가능했는지 공유하고자 한다.

 

뤼튼과 명령어 대화

 

AI에게 "맥 운영체제에서 여러개의 파일을 랜덤 한 파일이름으로 바꾸고 싶어. 자동으로 바뀌는 방법이 있을까?"라고 물어보았다. 그리고 AI는 자동으로 스크립트를 만들어주고, 그 스크립트에 대한 설명도 해주었다.

 

cd /path/to/your/directory
for file in *; do
  mv "$file" $(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1).jpg
done

 

뤼튼과 명령어 대화

그래서 랜덤 숫자가 아닌 랜덤 알파벳 배열로 바꾸는 방법도 물어보았다. 역시 멋지게 답변해 주는 AI

 

cd /path/to/your/directory
for file in *; do
  mv "$file" $(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1).jpg
done

 

하지만 나는 전형적인 문과생으로 bash가 뭔지, 디렉토리가 뭔지도 몰랐다.

 

그래서 이걸 어떻게 응용할지 물어보았다.

 

뤼튼과 명령어 대화

 

 

cd ~/Documents/images

 

for file in *; do
  mv "$file" $(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1).jpg
done

 

호오. 터미널이라는 프로그램으로 하면 되는구나. 하지만 이렇게 쉽게 될 리가 없지. 어김없이 오류가 떴다.

 

 

뤼튼과 명령어 대화

 

뭔지 모르겠지만 권한 문제로 안된다는 것 같은데, 바로 해결책까지 알려주는 우리의 착한 AI. 

 

난 여기서 한 발자국 더 나아가 보기로 했다. 이전에 비해서 편해졌지만, 터미널을 켜고 스크립트를 작성하고 하는 과정마저 귀찮다는 생각에, 버튼 하나로 뚝딱 완성되는 자동화에도 도전해 보기로 했다.

 

뤼튼과 명령어 대화

 

#!/bin/bash

cd /path/to/your/directory
for file in *; do
  mv "$file" $(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1).jpg
done

 

무슨 말인지 전혀 이해를 못 하겠지만 하라는 대로만 하면 된다는 거지? 그런데 Automator로 실행 앱을 만들 수 있다는 것에 눈이 간 나는, 그거까지 물어보고 말았다.

 

뤼튼과 명령어 대화

for file in /path/to/your/directory/*; do
  mv "$file" $(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1).jpg
done

 

과연 나는 한 번에 AI의 도움을 받아 Automator로 자동화 앱을 만들 수 있을까요?

 

to be contined...

320x100

+ Recent posts