如何修复这个Apple脚本外壳脚本组合以接受引号?

如何解决如何修复这个Apple脚本外壳脚本组合以接受引号?

首先,很抱歉,这篇文章很长,我试图尽我所能并且简洁明了。如果您觉得无聊或有其他问题,请按照自己的节奏阅读,我会及时答复。

重要的是我想说我对脚本一无所知,并且(不想听起来像个混蛋)我不想自己学它,因为我的大脑太油炸了,无法学到需要体面的记忆,组织或专注的东西由于未公开的原因,我只想修复脚本。

虽然我不是白痴,但是我可以运行终端或脚本编辑器并按照说明进行操作,并插入内容并给出错误结果。

该脚本从脚本编辑器运行,涉及ifttt,webhooks,spotify,applescript和shellscript,但脚本是其中的重要部分,因为它已损坏。

基本上,脚本会将当前正在播放的Spotify歌曲添加到预定义的播放列表中,效果很好,但是,如果歌曲标题中带有引号(单引号或双引号),则会给出错误消息(每种情况下会出现不同的错误消息),而不是添加这些歌曲,很多歌曲都有这些歌曲。

因此它对我来说基本上没有用,因为对我来说,它的价值是从应用程序外部控制Spotify,就像我在看抽搐一样。

我尝试过在reddit上提问,从freelancer网站和Apple支持论坛上聘请了自由职业者,人们尝试并提供了一些建议,但是他们没有用,所以这是我最后一次尝试的网站之一,对我来说非常重要之所以可以使用此脚本,是因为如果没有它我将无法进行适当的音乐发现,但它却被破坏了。

对于背景知识,这是我最初逐步进行的教程,以使脚本正常工作(适用于标题中没有引号的歌曲)。

https://medium.com/@l.krobbach/how-to-automatically-add-your-current-playing-song-to-a-spotify-playlist-on-mac-using-d87a0315475d

这是我在脚本终端中运行的脚本

if application "Spotify" is running then
    tell application "Spotify"
        if player state is playing then
            set ArtistName to (get artist of current track)
            set SongName to (get name of current track)
        end if
    end tell
end if
do shell script " curl -X POST -H \"Content-Type: application/json\" -d '{\"value1\":\"" & songname & "\",\"value2\":\"" & ArtistName & "\"}' https://maker.ifttt.com/trigger/add/with/key/REPLACEME"

当我实际运行它时,我将我的webhooks密钥替换为REPLACEME,但被告知不要在线共享该密钥。

如果我在带有1个引号的歌曲上运行它,它会在脚本编辑器结果中显示

错误“ sh:-c:第0行:寻找匹配的”“时出现意外的EOF sh:-c:第1行:语法错误:“文件意外结束”数字2

如果我在带有2个引号的歌曲上运行“它说

“错误请求”

如果我在没有引号的歌曲上运行它,则成功,并将歌曲添加到播放列表并说

“恭喜!您已经触发了添加事件”

来自不同站点的2个人独立地建议我用此脚本代替shellscript,这是有关引号形式的

do shell script " curl -X POST -H \"Content-Type: application/json\" -d '{\"value1\":\"" & quoted form of songname & "\",\"value2\":\"" & quoted form of ArtistName & "\"}' https://maker.ifttt.com/trigger/add/with/key/REPLACEME"

虽然不起作用

1个引用失败是

错误“ sh:-c:第0行:寻找匹配的”“时出现意外的EOF sh:-c:第1行:语法错误:“文件意外结束”数字2

2个引用失败是

错误“ sh:-c:第0行:意外令牌(' sh: -c: line 0: 附近的语法错误curl -X POST -H”内容类型:application / json“ -d'{” value1“:”'大仙女喷泉(摘自《塞尔达传说:时之笛》)-钢琴版本'“,” value2“:”'Koji Kondo'“}'https://maker.ifttt.com/trigger/add/with/key/REPLACEME'"数字2

(歌曲信息就是我在测试时播放的信息)。

有人也建议

set myJSONdata to "{\"value1\":\"" & SongName & "\",\"value2\":\"" & ArtistName & "\"}"
do shell script "echo curl -X POST -H \"Content-Type: application/json\" -d " & quoted form of myJSONdata & " hhttps://maker.ifttt.com/trigger/add/with/key/REPLACEME"

我不知道该在哪里插入,但是它也给出了错误消息

“ curl -X POST -H内容类型:application / json -d {” value1“:”OrphéeSuite-6. Orphee's Return“,” value2“:” Philip Glass“} hhttps://maker.ifttt .com / trigger / add / with / key / REPLACEME“

错误“未定义变量SongName。” “ SongName”中的编号-2753

根据我在脚本中的放置位置,他在提出建议后没有回复我,所以我不知道我是否搞砸了。

这个花了几个小时在自由职业者身上为我努力的可怜人尝试了,但是他没有苹果机,也没有使用applescript的经验,但是他在建议引用形式之后说applescript部分是问题,而不是shellscript。而且没有用,他尝试了

if application "Spotify" is running then
    tell application "Spotify"
        if player state is playing then
            set ArtistName to (get artist of current track)
            set SongName to (get name of current track)
        end if
    end tell
end if

set delim to "\""
set {myTID,AppleScript's text item delimiters} to {AppleScript's text item delimiters,{delim}}
set myList to text items of SongName
set AppleScript's text item delimiters to myTID
set listSize to count of myList

set counter = 0

repeat with myItem in myList
    if counter < listSize
       set SongName to SongName & delim
    end if
end repeat

do shell script " curl -X POST -H \"Content-Type: application/json\" -d '{\"value1\":\"" & songname & "\",\"value2\":\"" & ArtistName & "\"}' https://maker.ifttt.com/trigger/add/with/key/REPLACEME"

出现错误

语法错误,行尾不能在此数字之后,然后在脚本中突出显示set counter = 0行。

我真的不想再次尝试自由职业者,因为我不喜欢里程碑式付款截止日期的压力,并且在我缺乏与他们讨论脚本的经验时,我不愿意雇用人为我工作,我更喜欢接受在论坛上慢慢地。

因此,这就是我所拥有的全部信息,我们将不胜感激,将为您提供帮助,我会响应并尝试任何建议,如果有需要,我可以向贝宝(Paypal)补偿,如果有人愿意的话,我可以将其投入工作,谢谢。

解决方法

尝试使用if application "Spotify" is not running then return tell application "Spotify" if player state is not playing then return set ArtistName to (get artist of current track) set SongName to (get name of current track) end tell set json to quoted form of ("{\"value1\":" & quote & escapeDoubleQuotes(SongName) & quote & ",\"value2\":" & quote & escapeDoubleQuotes(ArtistName) & quote & "}") do shell script " curl -X POST -H \"Content-Type: application/json\" -d" & space & json & space & "https://maker.ifttt.com/trigger/add/with/key/REPLACEME" on escapeDoubleQuotes(theString) set {TID,text item delimiters} to {text item delimiters,quote} set textItems to text items of theString set text item delimiters to "\\\"" set quotedString to textItems as text set text item delimiters to TID return quotedString end escapeDoubleQuotes 添加引号,并显式转义双引号

{{1}}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-