首页 > 其他分享 >applescript book

applescript book

时间:2023-04-10 19:14:24浏览次数:41  
标签:set end applescript tell book dialog folder display

Apple Automator 2009
with AppleScript Bible

set randNumber to (random number (20)) as integer

if (randNumber > 10) then
	display dialog randNumber
end if
set theTime to "now"

if (theTime = "now") then
	display dialog "Fly!"
end if
set randNumber to (random number (20)) as integer
if (randNumber > 10) then
	display dialog "More than 10: " & randNumber
else
	display dialog "10 or less: " & randNumber
end if
set randNumber to (random number (20)) as integer
if (randNumber > 10) then
	display dialog "More than 10: " & randNumber
else if (randNumber ≥ 7 and randNumber ≤ 9) then
	display dialog "Between 7 & 9: " & randNumber
else if (randNumber ≥ 3 and randNumber < 7) then
	display dialog "Between 3 and 6: " & randNumber
else
	display dialog "It’s a 0, 1, or 2: " & randNumber
end if
repeat
	display dialog ¬
		"Please enter your first name:" default answer ""

	set firstName to text returned of result

	if firstName is not equal to "" then exit repeat

end repeat
repeat 3 times
	display dialog ¬
		"Please enter your first name:" default answer ""

	set firstName to text returned of result

	if firstName is not equal to "" then exit repeat
end repeat

if firstName = "" then display dialog ¬
	"You never gave us your first name!"
tell application "Finder"
	repeat with incrementValue from 1 to 3
		make new folder at desktop with properties ¬
			{name:incrementValue as string}
	end repeat
end tell
tell application "Finder"
	repeat with incrementValue from 1 to 50 by 5
		make new folder at desktop with properties ¬
			{name:incrementValue as string}
	end repeat
end tell
tell application "Finder"
	repeat with incrementValue from 10 to 1 by -1
		make new folder at desktop with properties ¬
			{name:incrementValue as string}
	end repeat
end tell
set loopCounter to 1
repeat until loopCounter = 30
	display dialog loopCounter
	set loopCounter to loopCounter + 1
end repeat
set firstName to ""
repeat until firstName is not equal to ""
	display dialog ¬
		"Please enter your first name:" default answer ""
	set firstName to text returned of result
end repeat
set myLogFile to (path to desktop as string) & "test.log"

tell application "Finder"
	repeat while (file myLogFile exists) = false
	end repeat
end tell

display dialog "The log file is on the desktop!"
set myList to {"dogs", "cats", "cars", "planes", "food"}

tell application "Finder"
	repeat with noun in myList
		make new folder at desktop with properties ¬
			{name:noun as string}
	end repeat
end tell
set destFolder to (path to current user folder)

display dialog "New Folder Name" default answer ""
set newFolder to the text returned of result

tell application "Finder"
	if (exists folder newFolder of destFolder) then
		display dialog "Sorry, that folder exists!"
	else
		make new folder at destFolder ¬
			with properties {name:newFolder}
		display dialog "New folder created!"
	end if
end tell
repeat with myvol from 1 to 10
    set volume myvol
    beep
    delay 1
end repeat
display dialog ¬
    "AppleScript rocks!" buttons {"Meh", "Right on!"} ¬
        default button "Right on!"

display dialog ¬
    "AppleScript rocks!" buttons {"Meh", "Right on!"} ¬
        default button 2

display dialog "what is your favorite color?" ¬
    default answer "blue"
display dialog ¬
	"what is your favorite color?" buttons {"blue", "red", "yellow"} ¬
	default button "blue"

set myColor to button returned of result
display dialog myColor
choose folder with prompt ¬
    "Choose a folder:" ¬
        default location (path to desktop folder)


choose folder with prompt ¬
    "Choose a folder:" ¬
        default location (path to desktop folder) ¬
    with multiple selections allowed
set myFiles to ¬
    choose file with prompt ¬
        "Choose file(s):" default location (path to documents folder) ¬
    with multiple selections allowed

set myList to {"red", "blue", "yellow", "green", "orange", "purple"}
choose from list myList


set myList to {"red", "blue", "yellow", "green", "orange", "purple"}
choose from list myList
set myColor to item 1 of result


set myList to {"red", "blue", "yellow", "green", "orange", "purple"}
choose from list myList ¬
    with prompt ¬
        "Favorite color?" default items {"blue"} ¬
    with multiple selections allowed
    set myColor to result
choose application with prompt ¬
    "Launch application(s)" ¬
    with multiple selections allowed
on addTwo(x, y)
    return x + y
end addTwo
display dialog addTwo(20,50)


set myListCount to count of {"eggs", "milk", "bread"}
set myRandom to (random number 100)

display dialog addTwo(myListCount, myRandom)
on addTwo(x, y)
    return x + y
end addTwo
on factorial(x)
    if x > 0 then
        return x * (factorial(x - 1))
    else
        return 1
    end if
end factorial

display dialog factorial(3)
set mathlib to (load script file ¬
"myerman:library:scripts:myerman:mathlib.scpt")

tell mathlib
    factorial(10)
end tell
on createFolder(newFolder, ExistingFolder)
    tell application "Finder"
        make new folder at folder ExistingFolder ¬
            with properties {name:newFolder}
    end tell
end createFolder
set myFolder to text returned of ¬
    (display dialog ¬
        "Choose new folder name" default answer "test")

set myDesktop to choose folder with prompt ¬
"Save folder in location" ¬
default location (path to desktop folder)
createFolder(myFolder, myDesktop)

on createFolder(newFolder, ExistingFolder)
    tell application "Finder"
        make new folder at folder ExistingFolder ¬
        with properties {name:newFolder}
    end tell
end createFolder

on trashIt(itemPath)
tell application "Finder"
delete item itemPath
end tell
end trashIt

set myDesktop to ¬
    (choose folder with prompt ¬
    "Choose a folder" default location (path to desktop folder))

set counter to countFolderItems(myDesktop)
display dialog counter

on countFolderItems(folderName)
    tell application "Finder"
        set theFolder to (folder folderName)
        set myCount to the count of (every item of theFolder)
        return myCount
    end tell
end countFolderItems
set myFile to choose file
set mySize to ¬
    size of (info for myFile) as string
display dialog (myFile as string) & ¬
return & "size: " & mySize
set myFiles to ¬
choose file with multiple selections allowed
getSizes(myFiles)

on getSizes(files_)
    set myString to ""
    repeat with file_ in files_
        set myFile to ((file_ as string) & return ¬
            & "size: " & size of (info for file_) ¬
            as string) & return & return
        set myString to myString & myFile
    end repeat
display dialog myString
end getSizes

https://files.cnblogs.com/files/Searchor/AppleAutomatorwithAppleScriptBible.zip

tell application "Finder"
    try
        set desktop picture to file (file_ as text)
    on error
        display dialog "Invalid file!" with icon 0
    end try
end tell

标签:set,end,applescript,tell,book,dialog,folder,display
From: https://www.cnblogs.com/Searchor/p/17303994.html

相关文章

  • 上线一天,4k star | Facebook:Segment Anything
    前言 本文介绍了FacebookAIResearch的SegmentAnything(SA)项目:用于图像分割的新任务、模型和数据集。在数据收集循环中使用该模型,它构建了迄今为止最大的分割数据集,在1100万张许可和尊重隐私的图像上有超过10亿个掩码。该模型被设计和训练为可提示的,因此它可以将零样本......
  • 荣耀magicbook安装Linux系统boot fail问题解决
    偶然网上冲浪,发现了Debian系的kalilinux有点意思,刚好手边有一台不怎么用的荣耀magicbook,于是准备装个双系统好不容易下完了kali的镜像,使rufus写入了U盘但是在安装过程中怎么安装都显示bootfail,切换了n个版本的Linux系统,发现还是这样,但是实测Debian11是可以进入引导项的最后所......
  • ansible-playbook之安装elasticsearch单机版
    一.准备环境:1.centos7环境2.安装ansible环境3.elasticsearch安装文件下载路径:  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.6.2-linux-x86_64.tar.gz4.elasticsearch安装主机,作者用192.168.126.129作为elasticsearch安装环境二.规划:1.变量规......
  • AppleScript key code
    https://eastmanreference.com/complete-list-of-applescript-key-codestellapplication"SystemEvents"keycode49endtellPlay:tellapplication"iTunes"toplayPause:tellapplication"iTunes"topause......
  • Window下,利用Anaconda2创建jupyter-notebook的python3环境方法
    转载自:https://www.cnblogs.com/ljy2013/p/8351067.html随着深度学习的火热,越来越多的人去学习和了解这门技术。而做算法的同学为了能够更快,更高效的写出相关的深度学习算法出来,需要比较方便的开发环境。今天主要介绍一下在jupyternotebook中,新增python3的环境,从而可以使用tenso......
  • 移动互联网时代,群星竞起,Facebook略显“苍白”
    随着移动互联网的迅猛发展,Facebook不得不面对的一个问题就是:它能否击败其他如雨后春笋般不断涌现的后起之秀,将它在互联网领域的辉煌成功移植到移动领域,成为移动社交网络的霸主?庞大的用户群确实是Facebook的巨大优势。Facebook的移动用户超过3.5亿,其中仅iOS应用的每月活跃用户就......
  • 林肯公园让听众用Facebook相册创作新歌MV
    看腻了现在明星们耍酷扮美或是认真歌唱毫无新意的MV?来搞点不一样的吧——用你Facebook上的照片做成专属你的音乐视频。LinkinPark的新歌LostintheEcho就用这样的有趣的方式进行推广。听众可以用自己Facebook里的照片作为素材打造自己的专属MV。用户只需在TakeThisLollipop视......
  • 180203 Jupyter Notebook and Markdown 插入图片位置并调整比例
    171111JupyterNotebook插入图片的4种方法MarkdownandimagealignmentExample:<imgstyle="float:right;"src="whatever.jpg"width="40%"><imgstyle="float:right;"src="https://timgsa.baidu.com/timg?image&qua......
  • Jupyter notebook中markdown书写格式
    Jupyternotebook中markdown书写格式前言:markdown是一种简洁明了的书写格式,适用于计算机专业编写博客等,包括加粗、图片、标题等级、代码等。markdown可用于多个平台,只要平台支持该形式即可使用,例如Jupyternotebook、博客园等都可以使用markdown格式书写。本篇主要提供一些m......
  • Facebook 《Embedding-based Retrieval in Facebook Search》
    背景这是Facebook应用在社交搜索召回上的一篇论文,与传统搜索场景(google,bing)不同的是,fb这边通常需要更加考虑用户的一些画像,比如位置,社交关系等。举个例子:fb上有很多JohnSmith,但用户使用查询“JohnSmith”搜索的实际目标人很可能是他们的朋友或熟人。或者一个cs专业的学生,......