在Automator中创建以指定文件名命名的新文件夹 [英] Create new folder named with a specified file name in Automator

查看:236
本文介绍了在Automator中创建以指定文件名命名的新文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个新文件夹,名称为用于输入的文件的文件名.

I want to create a new folder named with the filename of the file used for the input.

示例:

如果我将新服务与文件"test(test).jpg"一起使用,我想自动创建一个名为"test(test)"的文件夹.

If I use my new service with the file "test (test).jpg" I want to automatically create a folder named "test (test)".

推荐答案

要通过常规的Automator操作执行此操作,会有些麻烦,因为您需要保存原始输入,获取名称,创建文件夹,获取原始内容输入等等.您可以使用 Run AppleScript 操作一次完成大部分操作,尽管这取决于您要对原始输入和创建的文件夹路径进行什么操作.

To do this with regular Automator actions it gets a bit convoluted, since you need to save the original input, get the name, make the folder, get the original input back, etc. You can use a Run AppleScript action to do most of that in one go, although it depends on what you are wanting to do with the original input and created folder paths.

以下运行AppleScript 操作将使用输入项的名称创建新文件夹(请注意,服务可以传递多个项),并且仅传递原始输入.新文件夹是在同一父文件夹中创建的-不执行错误处理(名称重复等):

The following Run AppleScript action will create new folders with the name of the input items (note that a service can pass multiple items), and just passes the original input on. The new folders are created in the same parent folder - no error handling (duplicate names, etc) is performed:

on run {input, parameters} -- make new folders from base file names

    set output to {}

    repeat with anItem in the input -- step through each item in the input

        set anItem to anItem as text
        tell application "System Events" to tell disk item anItem
            set theContainer to path of container
            set {theName, theExtension} to {name, name extension}
        end tell
        if theExtension is in {missing value, ""} then
            set theExtension to ""
        else
            set theExtension to "." & theExtension
        end if
        set theName to text 1 thru -((count theExtension) + 1) of theName -- the name part

        tell application "Finder"
            make new folder at folder theContainer with properties {name:theName}
            set end of output to result as alias
        end tell
    end repeat

    return input -- or output
end run

这篇关于在Automator中创建以指定文件名命名的新文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆