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

+ Recent posts