by Aakaash Jois
通过Aakaash Jois
如何破解Mac并为其提供真正应得的精美壁纸 (How to hack your Mac and give it the gorgeous wallpapers it truly deserves)
Let’s face it. The default wallpapers on the Mac gets boring after a few weeks. And setting new wallpaper manually is tiresome. Well, what if I told you that I got my Mac greet me with a brand new, high resolution wallpaper every time I flip it open?
面对现实吧。 Mac上的默认壁纸会在几周后变得无聊。 手动设置新墙纸很麻烦。 好吧,如果我告诉您每次打开Mac时,我都会得到一台全新的高分辨率墙纸来迎接Mac,该怎么办?
If you’re a Chromecast user, you may be familiar with Chromecast Backdrop. Backdrop allows the Chromecast to display a slideshow of beautiful photos when it’s idle.
如果您是Chromecast用户,则可能对Chromecast Backdrop熟悉。 通过背景幕,Chromecast可以在闲置时以幻灯片形式显示精美照片。
While most users default to Facebook to post photos, a lot of photographers use Google+ to publish their work. Google selects some of these best photos to create brilliant slideshows.
尽管大多数用户默认使用Facebook发布照片,但是许多摄影师都使用Google+发布他们的作品。 Google会从其中一些最佳照片中选出精彩的幻灯片。
For a long time, this was exclusive to ChromeCast user. But a few months ago, Google released a nifty app for Mac called Google Featured Photos.
长期以来,这是ChromeCast用户专有的。 但是几个月前,谷歌为Mac发布了一个漂亮的应用程序,名为Google Featured Photos 。
You may be wondering why my title says “wallpaper” but then links to a “Screen Saver” app. Well, there’s the little trick. On a Mac, any screen saver can be made to run as a wallpaper with just one line of code.
您可能想知道为什么我的标题为“墙纸”,然后链接到“屏幕保护程序”应用程序。 好吧,这里有个小把戏。 在Mac上,只需一行代码即可使任何屏幕保护程序都可以作为墙纸运行。
First, you have to download and install the Google Featured Photos Screen Saver. Next, go to System Preferences → Desktop & Screen Saver and set the Google Featured Photos as the active screen saver. Now it’s time to run the magic code.
首先,您必须下载并安装Google特色照片屏幕保护程序 。 接下来,转到系统偏好设置 → 桌面和屏幕保护程序,然后将Google特色照片设置为活动的屏幕保护程序。 现在该运行魔术代码了。
编码时间! (Coding Time!)
Fire up Terminal and paste the below line of code. It will set your screen saver as your wallpaper.
启动终端并粘贴以下代码行。 它将您的屏幕保护程序设置为墙纸。
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &
编辑:苹果公司决定在High Sierra进行一些重组。 (EDIT: Apple decided to restructure a bit in High Sierra.)
If you are using High Sierra (or later), the ScreenSaverEngine.app
has been moved to a different location. Use the code below instead of the one above.
如果您使用的是High Sierra(或更高版本),则ScreenSaverEngine.app
已移至其他位置。 使用下面的代码,而不是上面的代码。
/System/Library/CoreServices/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &
Just replace all occurrences of Frameworks/ScreenSaver.framework/Resources
with CoreServices
and you will be good to go!
只需将所有出现的Frameworks/ScreenSaver.framework/Resources
替换为CoreServices
,您就会很高兴!
Cool, right?
酷吧?
The problem with running just that line of code is that if you close the Terminal window — or if your Mac goes to sleep — the screen saver closes and your wallpaper goes back to whatever it was by default. To handle this, we need to go a bit deeper.
仅运行该行代码的问题是,如果关闭“终端”窗口,或者Mac进入睡眠状态,则屏幕保护程序将关闭,并且墙纸将恢复为默认值。 为了解决这个问题,我们需要更深入一些。
To detect when the Mac sleeps and wakes up, we need a small piece of software called “Sleepwatcher.” You can download it here. Just open the file and your Mac will extract the downloaded file (sometimes it might have to be extracted twice). After extracting, you’ll get a “sleepwatcher_2.2” folder. Just move this folder to Desktop and run the following lines of code in the Terminal.
为了检测Mac何时睡眠和唤醒,我们需要一小块名为“ Sleepwatcher”的软件。 您可以在此处下载。 只需打开文件,您的Mac就会解压缩下载的文件(有时可能需要解压缩两次)。 解压缩后,您将获得一个“ sleepwatcher_2.2”文件夹。 只需将此文件夹移动到桌面,然后在终端中运行以下代码行即可。
sudo mkdir -p /usr/local/sbin /usr/local/share/man/man8
You might need to enter your password after pasting this line. Next, run:
粘贴此行后,您可能需要输入密码。 接下来,运行:
sudo cp ~/Desktop/sleepwatcher_2.2/sleepwatcher /usr/local/sbin
Then run:
然后运行:
sudo cp ~/Desktop/sleepwatcher_2.2/sleepwatcher.8 /usr/local/share/man/man8
Awesome! You have successfully installed Sleepwatcher.
太棒了! 您已经成功安装了Sleepwatcher。
Now let’s add the lines of code needed to make Sleepwatcher run the screen saver when your Mac wakes up, and kill the screen saver when your Mac goes to sleep.
现在,让我们添加必要的代码行,以使Sleepwatcher在Mac唤醒时运行屏幕保护程序,并在Mac进入睡眠状态时终止屏幕保护程序。
Sleepwatcher searches for and runs two files, .sleep
when the Mac sleeps, and .wakeup
when the Mac wakes up. We just need to create these 2 files in the user’s Home Directory.
对于Sleepwatcher搜索并运行两个文件, .sleep
时的Mac睡觉,和.wakeup
当MAC醒来。 我们只需要在用户的主目录中创建这两个文件。
In the Terminal, type nano ~/.wakeup
then paste the below code.
在终端中,键入nano ~/.wakeup
然后粘贴以下代码。
#!/bin/bashosascript -e 'do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background & EOF"'
Now press Control + X to exit. When it asks if you want to save the file, press Y and then press the enter key to confirm the file name. This will create the .wakeup
file. Now to create the .sleep
file.
现在按Control + X退出。 当询问您是否要保存文件时,请按Y ,然后按Enter键以确认文件名。 这将创建.wakeup
文件。 现在创建.sleep
文件。
Just like above, type nano ~/.sleep
and paste the below code.
与上面一样,键入nano ~/.sleep
并粘贴以下代码。
#!/bin/bash
osascript -e 'do shell script "kill `ps -ax | grep [S]creenSaver | cut -c1-6` EOF"'
Again, press Control + X to exit, Y to save, and then the enter key to confirm the file name. Now the .sleep
file will be created.
再次,按Control + X退出, Y保存,然后按Enter键确认文件名。 现在,将创建.sleep
文件。
In Terminal, run the below line of code.
在终端中,运行下面的代码行。
chmod 700 ~/.sleep ~/.wakeup
It changes the permissions for the newly created files so that it can be run by Sleepwatcher.
它更改了新创建文件的权限,以便可以由Sleepwatcher运行。
Now that you’ve created the scripts, you just need to add Sleepwatcher to launchd
so that it can start when the system starts, then continue to run in the background. Paste the following code code into your Terminal.
现在,您已经创建了脚本,只需要添加Sleepwatcher以launchd
它,以便它可以在系统启动时启动,然后继续在后台运行。 将以下代码粘贴到终端中。
cp ~/Desktop/sleepwatcher_2.2/config/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist ~/Library/LaunchAgents
This will copy the Sleepwatcher property list file so that it can be added to launchd
. Now just paste the code below into Terminal to add Sleepwatcher to launchd
.
这将复制Sleepwatcher属性列表文件,以便可以将其添加到launchd
。 现在,只需将下面的代码粘贴到Terminal中即可将Sleepwatcher添加到launchd
。
launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist
Awesome! You can now restart your Mac and the launchd
will run the Sleepwatcher scripts at the startup. Just put your Mac to sleep and wake it up. Then you’ll be welcomed with a beautiful wallpaper.
太棒了! 现在,您可以重新启动Mac,启动的Mac将在launchd
时运行Sleepwatcher脚本。 只需将Mac睡眠并唤醒它即可。 然后,您会得到美丽的墙纸的欢迎。
If you want to uninstall everything and go back to default, follow the link below.
如果您想卸载所有内容并恢复默认设置,请点击以下链接。
To uninstall, run the following lines in Terminal one by one.After running these, you can uninstall the Google Screen Saver and restart your Mac. It should be removed. Let me know…medium.com
要卸载,请在终端一一运行以下行。 运行这些文件后,您可以卸载Google屏幕保护程序并重新启动Mac。 应该将其删除。 让我知道… medium.com
I hope you enjoyed this short tutorial, and enjoy these beautiful wallpaper photos. If you liked this, hit the ❤️ and stay tuned for more.
我希望您喜欢这个简短的教程,并喜欢这些美丽的壁纸照片。 如果您喜欢这个,请打❤️并继续关注更多内容。
翻译自: https://www.freecodecamp.org/news/this-is-the-wallpaper-your-mac-truly-deserves-with-a-bit-of-coding-f3149bbeb51/