简体   繁体   English

AppleScript - 我怎样才能让这个字符串正确通过?

[英]AppleScript - How can I get this string to properly go through?

set UserName to do shell script "whoami"
set AD to do shell script ("dscl "/Active Directory/YC/All Domains/" read /Users/" & UserName)

My error: Expected “,” but found identifier我的错误:应为“,”,但找到标识符

So Im trying to find a users SMBHome in active directory because we map our drives based on that.所以我试图在活动目录中找到一个用户 SMBHome,因为我们基于它映射了我们的驱动器。 But the issue with that command is the double strings.但该命令的问题是双字符串。 "/Active Directory/YC/All Domains/" HAS to a string otherwise it wont properly queue. "/Active Directory/YC/All Domains/" 有一个字符串,否则它不会正确排队。

But to do shell script ("COMMAND HERE") has to be a string as well..但是要执行shell脚本(“COMMAND HERE”)也必须是一个字符串..

How do I combat this?我该如何解决这个问题?

And is there a easier way todo this?有没有更简单的方法来做到这一点?

Full script:完整脚本:

set UserName to do shell script "whoami"
set AD to do shell script ("dscl "/Active Directory/YC/All Domains/" read /Users/" & UserName)

if AD contains "StaffShare" then
    set SMBHome to "smb://domain/StaffShare"
else
    set SMBHome to "smb://domain/EmployeeShare"
end if

set mounted_disk to list disk

mount volume SMBHome as user name UserName

Nevermind, I actually figured it out.没关系,我真的想通了。 Similar to Lua "dscl \\"/Active Directory/YC/All Domains/\\" read /Users/" & UserName类似于 Lua "dscl \\"/Active Directory/YC/All Domains/\\" read /Users/" & UserName

Although Im still up to see if anyone has any better solutions for this.虽然我仍然想看看是否有人对此有更好的解决方案。 :) :)

You can use single quotes:您可以使用单引号:

set AD to do shell script "dscl '/Active Directory/YC/All Domains/' read $HOME"

But the way you've done it, by escaping the double quotes, it perfectly legit.但是你这样做的方式,通过转义双引号,它完全合法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM