mac上shell扫描目录并放到弹框列表中

2024-05-11 0 1
手机查看
result=$(Find /Users/wish/_data/我的笔记 -not -path '*/\.*' -type d -exec printf "%s/\n" {} \;)
result=$(echo $result)


# 使用 IFS 空格来分割字符串,并将结果赋值给数组
IFS=' ' read -ra options <<< "$result"

# 将Bash数组转换为AppleScript可接受的格式
escaped_options=$(IFS=','; echo "${options[*]}" | sed 's/,/","/g;s/^/"/;s/$/"/')

# 使用AppleScript弹出选择列表
read -r selectedOption < <(osascript -e "
    tell application \"System Events\"
        activate
        set userChoice to choose from list (${escaped_options}) with title \"请选择目标文件夹\" with prompt \"请选择:\"
        return userChoice as text
    end tell
")

if [ "$selectedOption" == "false" ]; then
    echo '你放弃了本次移动,请您手动去下载文件夹选择移动!';
else
    echo "You chose: $selectedOption"
fi

# 获取进程ID
pid=$(pgrep -f myprocess)

# 检查是否找到了进程
if [ -n "$pid" ]; then
    # 杀死进程
    kill "$pid"
fi

Shell 弹窗确认框

# alert
osascript -e 'display alert "您放弃了本次移动,您可以去下载文件夹手动移动!" buttons {"好的"} default button 1'

# 重要通知
osascript -e 'display dialog "您放弃了本次移动,您可以去下载文件夹手动移动!" buttons {"好的"} default button 1 with title "温馨提醒"'

Shell 通知

osascript -e "display notification \"$filename 已保存成功!\" with title \"提示:\""

shelll 杀死进程

# 获取进程ID
pid=$(pgrep -f fswatch)

# 检查是否找到了进程
if [ -n "$pid" ]; then
    # 杀死进程
    kill "$pid"
fi

What do you think?
  • 点赞
    0
    点赞
  • 踩一下
    0
    踩一下
  • 酷毙了
    0
    酷毙了
  • 不屑
    0
    不屑
  • 尴尬
    0
    尴尬
  • 无聊
    0
    无聊
Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v3.5.6